Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 478
Kevin S Avatar asked Jan 30 '26 21:01

Kevin S


1 Answers

Try this

string dateString = "00:02:52 APRIL 11, 2013 GMT";
DateTime dt = DateTime.Parse(dateString).ToUniversalTime();
like image 121
Sachin Avatar answered Feb 02 '26 16:02

Sachin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!