在我们的应用程序服务器中以这样的格式给出日期时间字符串
"2013-01-14 T 06:33 PST"
和"2013-01-14 T 06:33 PDT"
或"2013-01-14 T 06:33 PLT"
我如何解析这些字符串并在 C# 中获取 DateTime?
获得日期时间后,您可以使用TimeZoneInfo
DateTime dateTime = DateTime.Parse("2013-01-14 T 06:33");
TimeZoneInfo PST = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
TimeZoneInfo yourZone = TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time"); //For example
DateTime yourLocalTime = TimeZoneInfo.ConvertTime(dateTime, PST , yourZone );
试试这个: -
DateTime dt1 = DateTime.ParseExact("2013-01-14 21:09:06 PST".Replace("PST", "+2"), "yyyy-mm-dd HH:mm z", culture);
DateTime dt2 = DateTime.ParseExact("2013-01-14 21:09:06 PDT".Replace("PDT", "+2"), "yyyy-mm-dd HH:mm z", culture);
DateTime dt3 = DateTime.ParseExact("2013-01-14 21:09:06 PLT".Replace("PLT", "+2"), "yyyy-mm-dd HH:mm z", culture);