【问题标题】:Time format of datetime field in .net [duplicate].net中日期时间字段的时间格式[重复]
【发布时间】:2014-05-07 19:49:41
【问题描述】:

我有一个日期时间字段,其中显示日期时间为 11/03/14 12:00 AM。我怎样才能将此时间转换为 00:00 而不是 12:00 AM。

我试过了

    DateTime.ToString("hh:mm tt")

【问题讨论】:

  • 您的意思是 24 小时制?你要什么格式。你需要什么输出
  • 好吧,你真的不需要转换日期时间值。你只需要指定你想要的输出格式。

标签: c# .net time


【解决方案1】:

你需要先转换成DateTime,然后才能使用ToShortDateString

DateTime dt = DateTime.ParseExact("11/03/14 12:00 AM", "dd/MM/yy hh:mm tt", CultureInfo.InvariantCulture);
string result = dt.ToShortDateString();

阅读:http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多