Parse the string today with the format "PST"

In our application server, a date time string is given in a format similar to "2013-01-14 T 06:33 PST" and "2013-01-14 T 06:33 PDT" or "2013-01-14 T 06:33 PLT"

How can I parse these lines and get a DateTime in C #?

+4
source share
2 answers

Try the following: -

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

Once you get the date, you can do the conversion using 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 ); 
0
source

All Articles