【问题标题】:Need to convert date format in different way in c#? [closed]需要在 C# 中以不同的方式转换日期格式? [关闭]
【发布时间】:2013-06-03 11:02:33
【问题描述】:

我需要在 C# 中转换以下日期格式

 Actual   : 5/20/2010 3:01:18 PM ==> (IST)
 Required : 20 May 2010 09:31:18 AM ==> (GMT)

C#中有内置函数吗?

【问题讨论】:

  • 时间=5/20/2010 3:01:18 PM; DateTime date = DateTime.ParseExact(Time, "dd MMM yyyy", null);
  • 您发布的日期时间字符串与ParseExact 中的格式字符串完全不匹配。
  • 而不是分析问题是否有研究工作...请尝试给出一些有用的解释....刚才我正在学习在堆栈溢出中发布并学习 c# ...你可以确定看到我的声誉点:-(

标签: c# date string-formatting


【解决方案1】:

这个问题一直是asked before(虽然略有不同)。
这应该可以。

DateTime date = DateTime.ParseExact("d/MM/yyyy h:mm:ss tt", text, CultureInfo.InvariantCulture);
string newText = date.ToString("dd MMM yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

另外,请参阅documentation about date format strings

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-07
    • 2016-11-06
    相关资源
    最近更新 更多