如果我运行以下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文化与标准不同


基础教程推荐
- 【源码】c#编写的安卓客户端与Windows服务器程序进行网络通信 2023-09-18
- C# 模拟浏览器并自动操作的实例代码 2023-03-03
- C#单线程和多线程的端口扫描器应用比较详解 2023-06-27
- Unity基于ShaderLab实现光照系统(着色器代码实现小结) 2023-05-11
- 探秘Unity游戏开发中的状态设计模式 2023-07-19
- C#实现简易灰度图和酷炫HeatMap热力图winform(附DEMO) 2023-05-10
- C# SDK实现百度云OCR的文字识别功能 2023-01-06
- Razor C# – 从数据库中获取数据 2023-11-09
- Unity多语言转换工具的实现 2023-03-03
- c#中task与thread的区别及使用讲解 2023-06-14