今天有个测试需求要验证一个时间是否被显示为本地时间格式,翻了翻google,自己又做了些试验,终于找出来这么个方法。留下来以备日后查用。
string dateNeedToParse = "02/10/2014";
DateTime myDate =
DateTime.Now;
bool compareResult = false;
compareResult = DateTime.TryParseExact(dateNeedToParse,
System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern.ToString(),
System.Globalization.DateTimeFormatInfo.CurrentInfo,
System.Globalization.DateTimeStyles.AssumeLocal, out myDate);
Console.Write("The date " + dateNeedToParse);
if
(compareResult)
{
Console.Write(" can");
}
else
{
Console.Write(" cannot");
}
Console.Write(" be parsed to local system date format!");
Console.ReadKey();
原文:http://www.cnblogs.com/Lihao2013/p/3543036.html