5

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

Community
  • 1
  • 1
Rajbir Singh
  • 1,641
  • 6
  • 23
  • 46

1 Answers1

15

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);
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • @DorCohen you got the answer from this question http://stackoverflow.com/questions/6941839/how-to-convert-pdt-time-string-to-datetime. Do you think is this ok? – Adrian Iftode Apr 24 '12 at 11:27
  • Oded thanks for your help but it has one issue. It is not giving the correct time. The dt has value 4/23/2012 6:11:33 PM. Can you please sort out it . – Rajbir Singh Apr 24 '12 at 11:33
  • @RajbirSingh - No, I can't. It depends on what timezone the computer is on. On my computer I get "23/04/2012 13:41:33". What do you think the "correct time" should be? – Oded Apr 24 '12 at 11:36
  • it's ok. Anyways thanks Oded. – Rajbir Singh Apr 24 '12 at 11:41