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

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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

回答1:

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); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!