public static DateTime LocalTime2GreenwishTime(DateTime lacalTime)
{
TimeZone localTimeZone = System.TimeZone.CurrentTimeZone;
TimeSpan timeSpan = localTimeZone.GetUtcOffset(lacalTime);
DateTime greenwishTime = lacalTime - timeSpan;
return greenwishTime;
}
public static DateTime GreenwishTime2LocalTime(DateTime greenwishTime)
{
TimeZone localTimeZone = System.TimeZone.CurrentTimeZone;
TimeSpan timeSpan = localTimeZone.GetUtcOffset(greenwishTime);
DateTime lacalTime = greenwishTime + timeSpan;
return lacalTime;
}
PS:关于非DateTime类型的字符串格式的转换
string strDate ="Mon Aug 15 2011 00:00:00 GMT+0800"; DateTime date = DateTime.ParseExact(strDate, @"ddd MMM dd yyyy HH:mm:ss GMT+ffff", CultureInfo.CreateSpecificCulture("en-US")); Response.Write(date.ToString());转载于:https://blog.51cto.com/harlen/1247229