如何将日期时间字符串转换为当前区域性日期时间字符串 [英] How to convert a Datetime string to a current culture datetime string

查看:114
本文介绍了如何将日期时间字符串转换为当前区域性日期时间字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有串说,在美国英语文化2011/12/1我目前该机文化是英国英语是DD / MM / YYYY格式。如何转换为2011/12/1 2011/1/12。我曾尝试下面的格式。

  System.DateTime.Parse(结果,System.Threading.Thread.CurrentThread.CurrentCulture)
              的ToString(System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern)

但我无法看到任何输出。

-Lokesh。


解决方案

 的DateTimeFormatInfo usDtfi =新的CultureInfo(EN-US,FALSE).DateTimeFormat;
的DateTimeFormatInfo ukDtfi =新的CultureInfo(EN-GB,FALSE).DateTimeFormat;
字符串结果= Convert.ToDateTime(12/01/2011,usDtfi)的ToString(ukDtfi.ShortDatePattern);

这将这样的伎俩^^

I have string say "12/1/2011" in English US culture my current machine culture is English Uk which is "dd/mm/yyyy" format. How to convert the 12/1/2011 to 1/12/2011. I have tried the below format.

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

but i could not able to see any output.

-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);

This will do the trick ^^

这篇关于如何将日期时间字符串转换为当前区域性日期时间字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆