如何将日期时间字符串转换为当前区域性日期时间字符串

2024-02-28

我有一个字符串,用美国英语文化表示“12/1/2011”,我当前的机器文化是英国英语,格式为“dd/mm/yyyy”。如何将 12/1/2011 转换为 1/12/2011。我尝试过以下格式。

System.DateTime.Parse(result,System.Threading.Thread.CurrentThread.CurrentCulture)
              .ToString(System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern)

但我看不到任何输出。

-Lokesh.


DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;
DateTimeFormatInfo ukDtfi = new CultureInfo("en-GB", false).DateTimeFormat;
string result = Convert.ToDateTime("12/01/2011", usDtfi).ToString(ukDtfi.ShortDatePattern);

这样就可以解决问题了^^

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将日期时间字符串转换为当前区域性日期时间字符串 的相关文章

随机推荐