Marco Shaw <marcoDOTshaw_@_gmailDOTcomwrote:
Some examples in datetime format:
Thu, 25 Jan 2007 10:22:39 -0500
Thu, 25 Jan 2007 09:12:17 -0800
Thu, 25 Jan 2007 10:26:04 -0800
Thu, 25 Jan 2007 10:27:26 -0800
Thu, 25 Jan 2007 19:28:28 +0000
What's the easiest way to get these into my local timezone (AST-Atlantic
Standard Time)?
Change them to GMT, then do -0400?
Try this: (works on my box, but I'm in GMT!)
using System;
using System.Globalization;
class Program
{
static void Main(string[] args)
{
string[] data = new string[]
{"Thu, 25 Jan 2007 10:22:39 -0500",
"Thu, 25 Jan 2007 09:12:17 -0800",
"Thu, 25 Jan 2007 10:26:04 -0800",
"Thu, 25 Jan 2007 10:27:26 -0800",
"Thu, 25 Jan 2007 19:28:28 +0000"};
foreach (string x in data)
{
Parse(x);
}
}
static void Parse (string x)
{
DateTime dt = DateTime.ParseExact
(x, "ddd, dd MMM yyyy HH:mm:ss zzz",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal);
dt = dt.ToLocalTime();
Console.WriteLine (dt);
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too