I am looking to convert this time: Mon, 25 03 2013 00:00:00 GMT
into US EST. I know that this has been posted before here:Time zone conversion in C# but I am still getting errors having to do something with the string not being exactly right.
Here is my code:
var dateString = "Mon, 25 03 2013 00:00:00 GMT";
var date = Convert.ToDateTime(dateString);
var result = TimeZoneInfo.ConvertTime(date, TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time"));
Console.WriteLine(result);
Here is my error:
Unhandled Exception: System.FormatException: String was not recognized as a valid DateTime.
at System.DateTime.Parse (System.String s, IFormatProvider provider, DateTimeStyles styles) [0x00000] in :0
at System.DateTime.Parse (System.String s, IFormatProvider provider) [0x00000] in :0
at System.DateTime.Parse (System.String s) [0x00000] in :0
at System.Convert.ToDateTime (System.String value) [0x00000] in :0 at Program.Main () [0x00000] in :0
I have tried changing the date from 03
to Mar
but I was unable to even get that to work. I have also tried the code in the other forum just to see if that even worked, but I was unsuccessful. I fully understand what the code is trying to do, but I just don't understand why there are errors being thrown.
Any help would be much appreciated! Thanks!