Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert this 05:41:33 Apr 23, 2012 PDT value to datetime in C#? [duplicate]

Tags:

c#

asp.net

Possible Duplicate:
Parse DateTime with timezone of form PST/CEST/UTC/etc
How to Convert PDT Time string to DateTime

I want to convert this value 05:41:33 Apr 23, 2012 PDT to datetime .

i am trying this but it is giving an error.

 DateTime dt = Convert.ToDateTime("05:41:33 Apr 23, 2012 PDT");

Please help me guys how we can do it in C#.

Thanks,Rajbir

like image 871
Rajbir Singh Avatar asked Apr 24 '12 11:04

Rajbir Singh


1 Answers

The PDT is not recognizable as a timezone by any of the parsing options for a DateTime in the BCL.

If you convert it to -0700 before parse it will parse ok.

string correctedTZ = "05:41:33 Apr 23, 2012 PDT".Replace("PDT", "-0700");
DateTime dt = Convert.ToDateTime(correctedTZ);
like image 57
Oded Avatar answered Sep 25 '22 01:09

Oded