我必须在Javascript中预先验证一个字符串,该字符串将是c#中的DateTime。 DateTime解析使用InvariantCulture。
有没有人知道为InvariantCulture定义的DateTime格式?
答案 0 :(得分:18)
从此处汇编信息: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
答案 1 :(得分:7)
它很容易测试。
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));
}
}
输出:
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
DotNetFiddle上的代码。
答案 2 :(得分:1)
它或多或少与en-us相同,但用作24小时时间而不是12小时上午/下午并填写完整的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"
答案 3 :(得分:1)
yyyy-MM-ddTHH:mm:ss.fffffffzz
ddd, dd MMM yyyy HH:mm:ss
yyyy-MM-ddTHH:mm:ss
yyyy-MM-dd HH:mm:ssZ
来源[1]:https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings