I'm trying to specify the timezone on a string that I am passing to DateFormat.parse
. We're currently using .net framework 2.0. Current code is
DateTimeFormatInfo DATE_FORMAT = CultureInfo.CurrentCulture.DateTimeFormat;
DateTime first = DateTime.Parse("Wed, 31 Oct 2007 8:00:00 -5", DATE_FORMAT);
But then when I do first.ToString("r")
, the result is
Wed, 31 Oct 2007 09:00:00 GMT
What am I doing wrong? I also tried using DateTime.SpecifyKind
method to set my DateTime object's Kind to Local, but it seems like you would need to specify the kind as local before you parse the string, if the timezone is part of the string.
My local timezone is EDT, that's what I'm ultimately trying to get this date to.
Edit - our solution:
input :
DateTime first = DateTime.SpecifyKind(DateTime.Parse("OCT 31, 2007 8:00 AM", DATE_FORMAT), DateTimeKind.Local);
output :
first.ToLocalTime().ToString("our format")
Still haven't found a way to get time zone abbreviation, like 'EDT'.