【问题标题】:Convert a string format to formated date style [duplicate]将字符串格式转换为格式日期样式[重复]
【发布时间】:2016-04-05 06:37:36
【问题描述】:

我使用 asp.net,我有一个字符串格式“01/29/2016”。如何将此字符串格式化为“29/01/2016”输出?因为该值将在报表过滤时处理,

谢谢,

【问题讨论】:

标签: c# asp.net vb.net string date


【解决方案1】:

首先将您的字符串格式转换为日期时间。使用以下

DateTime YourDate= DateTime.ParseExact(
            "01/29/2016",
            "MM/dd/yyyy",
            CultureInfo.InvariantCulture);

然后将此日期时间转换为您需要的格式。

string myDateString = YourDate.ToString("dd/MM/yyyy");

【讨论】:

    【解决方案2】:

    如果是日期值,您可以使用 Date.toString (dd/MM/yyyy) 如果不事先使用 DateTime.Parse(字符串)

    【讨论】:

      【解决方案3】:
      DateTime.ParseExact (myString, "d", CultureInfo.InvariantCulture).ToString (@"dd/MM/yyyy");
      

      这应该对你有用

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-06-16
        • 2020-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多