/// <summary>
/// 本地时间转成GMT时间
/// </summary>
public static string ToGMTString(DateTime dt)
{
return dt.ToUniversalTime().ToStrin("r");
}
/// <summary>
/// 本地时间转成GMT格式的时间
/// </summary>
public static string ToGMTFormat(DateTime dt)
{
return dt.ToString("r") + dt.ToString("zzz").Replace(":", "");
}
/// <summary>
/// GMT时间转成本地时间
/// </summary>
/// <param name="gmt">字符串形式的GMT时间</param>
/// <returns></returns>
public static DateTime GMT2Local(string gmt)
{
DateTime dt = DateTime.MinValue;
try
{
string pattern = "";
if (gmt.IndexOf("+0") != -1)
{
gmt = gmt.Replace("GMT", "");
pattern = "ddd, dd MMM yyyy HH':'mm':'ss zzz";
}
if (gmt.ToUpper().IndexOf("GMT") != -1)
{
pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
}
if (pattern != "")
{
dt = DateTime.ParseExact(gmt, pattern, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal);
dt = dt.ToLocalTime();
}
else
{
dt = Convert.ToDateTime(gmt);
}
}
catch
{
}
return dt;
}
/// 本地时间转成GMT时间
/// </summary>
public static string ToGMTString(DateTime dt)
{
return dt.ToUniversalTime().ToStrin("r");
}
/// <summary>
/// 本地时间转成GMT格式的时间
/// </summary>
public static string ToGMTFormat(DateTime dt)
{
return dt.ToString("r") + dt.ToString("zzz").Replace(":", "");
}
/// <summary>
/// GMT时间转成本地时间
/// </summary>
/// <param name="gmt">字符串形式的GMT时间</param>
/// <returns></returns>
public static DateTime GMT2Local(string gmt)
{
DateTime dt = DateTime.MinValue;
try
{
string pattern = "";
if (gmt.IndexOf("+0") != -1)
{
gmt = gmt.Replace("GMT", "");
pattern = "ddd, dd MMM yyyy HH':'mm':'ss zzz";
}
if (gmt.ToUpper().IndexOf("GMT") != -1)
{
pattern = "ddd, dd MMM yyyy HH':'mm':'ss 'GMT'";
}
if (pattern != "")
{
dt = DateTime.ParseExact(gmt, pattern, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal);
dt = dt.ToLocalTime();
}
else
{
dt = Convert.ToDateTime(gmt);
}
}
catch
{
}
return dt;
}
/// <summary>
/// 日期转换
/// </summary>
/// <param name="time">新浪微博中返回的类似"Mon Oct 18 12:28:54 +0800 2010"这样的时间</param>
/// <returns>DateTime</returns>
public static DateTime ConverDateTime(string time)
{
string[] cx = time.Split(' ');
System.Globalization.DateTimeFormatInfo g = new System.Globalization.DateTimeFormatInfo();
g.LongDatePattern = "dd MMMM yyyy";
DateTime DT = DateTime.Parse(string.Format("{0} {1} {2} {3}", cx[2], cx[1], cx[5], cx[3]), g);
return DT;
}
/// 日期转换
/// </summary>
/// <param name="time">新浪微博中返回的类似"Mon Oct 18 12:28:54 +0800 2010"这样的时间</param>
/// <returns>DateTime</returns>
public static DateTime ConverDateTime(string time)
{
string[] cx = time.Split(' ');
System.Globalization.DateTimeFormatInfo g = new System.Globalization.DateTimeFormatInfo();
g.LongDatePattern = "dd MMMM yyyy";
DateTime DT = DateTime.Parse(string.Format("{0} {1} {2} {3}", cx[2], cx[1], cx[5], cx[3]), g);
return DT;
}