Analyze the datetime
When trying to analyze the international date time strings including time zone abbreviations (such as "PST" or "UTC"),
may be difficult to identify abbreviations. To overcome this problem, consider replacing the abbreviation to the corresponding offset.
DateTime.ParseExact
Using , you can specify regional, which will affect the analysis of the date and time value. For example:
CultureInfo
Format string is critical to correctly analyze the date of time. The "custom date and time format string" document does not clearly mention the format description symbol in the time zone in the form of "PST/CEST/GMT/UTC".
<code class="language-csharp">CultureInfo culture = CultureInfo.CreateSpecificCulture("nl-BE");</code>
or, you can use the following format string:
<code class="language-csharp">DateTime dt1 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+2"), "dd-MMM-yy HH:mm:ss z", culture);</code>
"ZZ" for two -digit offset:
<code class="language-csharp"> DateTime dt2 = DateTime.ParseExact("24-okt-08 21:09:06 CEST".Replace("CEST", "+02"), "dd-MMM-yy HH:mm:ss zz", culture);</code>
The above is the detailed content of How to Accurately Parse DateTime Strings with Time Zone Abbreviations in C#?. For more information, please follow other related articles on the PHP Chinese website!