I have to pre-validate in Javascript a string that will be a DateTime in c#. The DateTime parse uses InvariantCulture.
Does anyone know the DateTime formats defined for InvariantCulture?
I have to pre-validate in Javascript a string that will be a DateTime in c#. The DateTime parse uses InvariantCulture.
Does anyone know the DateTime formats defined for InvariantCulture?
Compiling information from here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings
MM/dd/yyyy
dddd, dd MMMM yyyy
dddd, dd MMMM yyyy HH:mm
dddd, dd MMMM yyyy HH:mm:ss
MM/dd/yyyy HH:mm
MM/dd/yyyy HH:mm:ss
MMMM dd
yyyy-MM-ddTHH:mm:ss.fffffffK
ddd, dd MMM yyyy HH:mm:ss GMT
yyyy-MM-ddTHH:mm:ss
HH:mm
HH:mm:ss
yyyy-MM-dd HH:mm:ssZ
dddd, dd MMMM yyyy HH:mm:ss
yyyy MMMM
It's very easy to test.
public static void Main()
{
var d = DateTime.Now;
Console.WriteLine("Date format (long): {0}", d.ToString("D", CultureInfo.InvariantCulture));
Console.WriteLine("Date format (short): {0}", d.ToString("d", CultureInfo.InvariantCulture));
Console.WriteLine("Full format (long): {0}", d.ToString("F", CultureInfo.InvariantCulture));
Console.WriteLine("Full format (short): {0}", d.ToString("f", CultureInfo.InvariantCulture));
Console.WriteLine("Time format (long): {0}", d.ToString("T", CultureInfo.InvariantCulture));
Console.WriteLine("Time format (short): {0}", d.ToString("t", CultureInfo.InvariantCulture));
Console.WriteLine("General format (long): {0}", d.ToString("G", CultureInfo.InvariantCulture));
Console.WriteLine("General format (short): {0}", d.ToString("g", CultureInfo.InvariantCulture));
}
}
Output:
Date format (long): Monday, 16 October 2017
Date format (short): 10/16/2017
Full format (long): Monday, 16 October 2017 20:12:45
Full format (short): Monday, 16 October 2017 20:12
Time format (long): 20:12:45
Time format (short): 20:12
General format (long): 10/16/2017 20:12:45
General format (short): 10/16/2017 20:12
Code on DotNetFiddle.
Its more or less the same as en-us but uses as 24 hour time instead of 12 hour am/pm and fills in full MM/DD/YYYY.
var date1 = d.ToString(CultureInfo.InvariantCulture); // "05/21/2014 22:09:28"
var date2 = d.ToString(new CultureInfo("en-US")); // "5/21/2014 10:09:28 PM"
yyyy-MM-ddTHH:mm:ss.fffffffzz
ddd, dd MMM yyyy HH:mm:ss
yyyy-MM-ddTHH:mm:ss
yyyy-MM-dd HH:mm:ssZ
Sources [1]: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings