Home >Backend Development >C++ >How Do I Parse DateTime Strings with Time Zones like PST, CEST, and UTC?
DateTime string containing time zone information (such as PST, CEST, and UTC) string
Solution
In the above code fragment, the original time zone abbreviation "CEST" is replaced with the corresponding offset "2", "02" and "02:00". Format string "Z", "ZZ" and "ZZZ" represent the time zone abbreviation of a letter, the time zone abbreviation of the two letters, and the number of symbol numbers with a optional minute decimal.
<code class="language-csharp">CultureInfo culture = CultureInfo.CreateSpecificCulture("nl-BE"); 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);</code>
The above is the detailed content of How Do I Parse DateTime Strings with Time Zones like PST, CEST, and UTC?. For more information, please follow other related articles on the PHP Chinese website!