Created
March 3, 2018 19:39
-
-
Save phillijw/f28f02474cf1313a2cbb8d1055de513c to your computer and use it in GitHub Desktop.
zzz in .net DateTime ToString formatter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
var utcEpoch = DateTime.Parse("1970-01-01", CultureInfo.InvariantCulture, | |
DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); | |
Console.WriteLine(utcEpoch.Kind); | |
Console.WriteLine(utcEpoch.ToString("o")); | |
Console.WriteLine(utcEpoch.ToString("zzz")); | |
} | |
Console.WriteLine("-----------"); | |
{ | |
var utcEpoch = DateTime.Parse("1970-01-01", CultureInfo.InvariantCulture, | |
DateTimeStyles.AssumeUniversal); | |
Console.WriteLine(utcEpoch.Kind); | |
Console.WriteLine(utcEpoch.ToString("o")); | |
Console.WriteLine(utcEpoch.ToString("zzz")); | |
} | |
Output: | |
Utc | |
1970-01-01T00:00:00.0000000Z | |
-06:00 | |
----------- | |
Local | |
1969-12-31T18:00:00.0000000-06:00 | |
-06:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget about DateTimeOffset. It provides an epoch time