Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active July 29, 2025 05:04
Show Gist options
  • Save guitarrapc/923c8ff97b9a78068fb3b8d8c574094b to your computer and use it in GitHub Desktop.
Save guitarrapc/923c8ff97b9a78068fb3b8d8c574094b to your computer and use it in GitHub Desktop.
Invariant Date and Formatter is not same as Windows

Windowws Date format on region settings for USA.

image
// Set invariant Culture to get none-localized date format, should be US style.
System.Globalization.CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
// See format with https://learn.microsoft.com/ja-jp/dotnet/standard/base-types/standard-date-and-time-format-strings
DateTime.Now.Dump("None"); // MM/dd/yyyy HH:mm:ss
DateTime.Now.ToLongDateString().Dump("ToLongDateString"); // DDD dd/MM/yyyy
DateTime.Now.ToString("o").Dump("o"); // yyyy-MM-ddTHH:mm:ss.SSSSSS+O
DateTime.Now.ToString("d").Dump("d"); // dd/MM/yyyy
DateTime.Now.ToString("D").Dump("D"); // DDD, dd MM yyyy
DateTime.Now.ToString("f").Dump("f"); // DDD, dd MM yyyy HH:mm
DateTime.Now.ToString("F").Dump("F"); // DDD, dd MM yyyy HH:mm:ss
DateTime.Now.ToString("g").Dump("g"); // dd/MM/yyyy HH:mm
DateTime.Now.ToString("G").Dump("G"); // dd/MM/yyyy HH:mm:ss
DateTime.Now.ToString("s").Dump("s"); // yyyy-MM-ddTHH:mm:ss
/*
None
07/29/2025 13:59:18
ToLongDateString
Tuesday, 29 July 2025
o
2025-07-29T13:59:18.0410173+09:00
d
07/29/2025
D
Tuesday, 29 July 2025
f
Tuesday, 29 July 2025 13:59
F
Tuesday, 29 July 2025 13:59:18
g
07/29/2025 13:59
G
07/29/2025 13:59:18
s
2025-07-29T13:59:18
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment