Kevin S
Kevin S

Reputation: 31

C# DateTime.Parse(someString)

I am working on a project and I get the following string representation of time and date, i.e. "00:02:52 APRIL 11, 2013 GMT". When I use the DateTime.Parse() method:

DateTime dt= DateTime.Parse(dateString);

string text = dt.ToString("hh:mm:ss MMM dd, yyyy ").ToUpper();

My output (text) is:

"05:02:52 APR 11, 2013 GMT"

and NOT

"00:02:52 APR 11, 2013 GMT"

I don't get why the hour (HH) has changed to 00 to 05. I traced my code through V.S. many times. All I am doing is truncating the month, APRIL to APR.

Would anyone please give me insight on what I'm doing wrong or missing?

Thanks!

Upvotes: 3

Views: 146

Answers (1)

Sachin
Sachin

Reputation: 40990

Try this

string dateString = "00:02:52 APRIL 11, 2013 GMT";
DateTime dt = DateTime.Parse(dateString).ToUniversalTime();

Upvotes: 1

Related Questions