Parse DateTime with time zone of form PST/CEST/UTC/etc

前端 未结 6 705
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 04:28

I\'m trying to parse an international datetime string similar to:

24-okt-08 21:09:06 CEST

So far I\'ve got something like:

         


        
6条回答
  •  悲&欢浪女
    2020-11-22 04:59

    AFAIK the time zone abbreviations are not recognized. However if you replace the abbreviation with the time zone offset, it will be OK. E.g.:

    DateTime dt1 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+2"), "dd-MMM-yy HH:mm:ss z", culture);
    DateTime dt2 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+02"), "dd-MMM-yy HH:mm:ss zz", culture);
    DateTime dt3 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+02:00"), "dd-MMM-yy HH:mm:ss zzz", culture);
    

提交回复
热议问题