【问题标题】:How can I convert string date to date using c#如何使用 c# 将字符串日期转换为日期
【发布时间】:2022-07-06 13:56:48
【问题描述】:

我有以下日期时间格式的字符串。

04-AUG-2022

我需要将其转换为以下日期格式。 04 August 2022。我该怎么做,我尝试了以下代码。

        string date = "04-AUG-2022";

        DateTime d = DateTime.ParseExact(date, "dd-MMMM-yyyy", CultureInfo.InvariantCulture);

但它显示,System.FormatException: 'String '04-AUG-2022' was not recognized as a valid DateTime.'

【问题讨论】:

标签: c# datetime


【解决方案1】:

就这样吧,

string date = "04-AUG-2022";
var formatedDate = DateTime.Parse(date).ToString("dd MMMM yyyy", CultureInfo.InvariantCulture);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2011-04-29
    相关资源
    最近更新 更多