This article explores the complexity of the strings that include internationalization date and time and time zone information (especially PST/CEST/UTC, etc.). "24-OKT-08 21:09:06 CEST" is an example that needs to identify the appropriate custom format string.
The document of the custom date and time format string may not be clearly provided to analyze the format string used to analyze this format time zone. However, there is a way to change the way, that is, replace the time zone abbreviation with the corresponding time zone offset.
Solution:
As shown in the answer, use the time zone offset (for example, "2") to replace the time zone abbreviation (eg, "cest") can successfully analyze the date and time string:
In order to adapt to different time zone offset formats, a variety of variants can be used:
<code>DateTime dt1 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+2"), "dd-MMM-yy HH:mm:ss z", culture);</code>
"02" is used in "HH" format
The above is the detailed content of How to Parse DateTime Strings with Time Zones like PST, CEST, and UTC?. For more information, please follow other related articles on the PHP Chinese website!