c#-.NET和Windows文化与标准不同

如果我运行以下C#代码var cultureInfo = new System.Globalization.CultureInfo(af); Console.WriteLine(cultureInfo.DateTimeFormat.ShortDatePattern);我得到yyyy-MM-dd的输出.但是,如果我在客户端上使用...

如果我运行以下C#代码

var cultureInfo = new System.Globalization.CultureInfo("af");       
Console.WriteLine(cultureInfo.DateTimeFormat.ShortDatePattern);

我得到yyyy-MM-dd的输出.

但是,如果我在客户端上使用momentjs并运行以下代码

var localeData = moment.localeData('af');
console.log(localeData._config.longDateFormat.L);

我得到DD / MM / YYYY的输出.

他们为什么不同?研究表明,momentjs可能是正确的.如果我在客户端输入日期,然后尝试在服务器上解析日期,则会出现问题.

解决方法:

var cultureInfo = new System.Globalization.CultureInfo("af");  

等于

af-ZA   Afrikaans - South Africa    0x0436  AFK

Date and time notation in South Africa

South Africa signed up to use ISO 8601 for date and time
representation through national standard ARP 010:1989 in 1998. The
most recent South African Bureau of Standards standard SANS 8601:2009
“… is the identical implementation of ISO 8601:2004, and is adopted
with the permission of the International Organization for
Standardization” and was reviewed in 2016.

日期备注

Even so, the old date format is still commonly used in the format
“dd/mm/yyyy”, with the “day month year” order being more common with
non-numeric month designations.

https://en.wikipedia.org/wiki/ISO_8601

YYYY-MM-DD  or  YYYYMMDD

.NET Framework Cultures with Date and Time String Formats

English Name                Abbreviation    ShortDate Format    
Afrikaans (South Africa)    af-ZA           yyyy/MM/dd  

老实说:moment.js似乎错了

本文标题为:c#-.NET和Windows文化与标准不同

基础教程推荐