<summary>
///local time to GMT time
///</summary> public
static string togmtstring (DateTime dt)
{return
dt. ToUniversalTime (). ToString ("R");
}
string s = togmtstring (DateTime.Now);
local time: 2011-9-29 15:04:39
The converted time is: Thu, Sep 07:04:39 GMT
<summary>
///local time to GMT format
///</summary> public
static string Togmtformat (DateTime DT )
{return
dt. ToString ("R") + dt. ToString ("zzz"). Replace (":", "");
}
string s = Togmtformat (DateTime.Now);
local time: 2011-9-29 15:04:39
The converted time is: Thu, Sep 15:04:39 gmt+0800
<summary>///GMT time to local time///</summary>///<param name= "GMT" > String form
GMT time </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, Syst Em.
Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal); DT = dt.
ToLocalTime (); }
else {dt = Convert.todatetime (GMT);
} catch {} return dt; }
DateTime dt1 = gmt2local ("Thu, Sep 07:04:39 GMT");
Converted Dt1:2011-9-29 15:04:39
DateTime DT2 = gmt2local ("Thu, Sep 15:04:39 gmt+0800");
Converted DT2:2011-9-29 15:04:39
Author: Zhu Huazhen