如果我运行以下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# WPF 父控件通过使用可视化树找到子控件的示例代码 2022-12-31
- C#委托用法详解 2023-05-22
- C# 创建EXCEL图表并保存为图片的实例 2022-11-28
- 浅入 .NET Core 中的内存和GC知识 2023-09-27
- C#把DataTable导出为Excel文件 2023-05-30
- C#公众号开发之给用户发红包 2022-12-30
- C#对集合进行排序 2023-05-25
- 详解C# 代码占用的空间 2022-12-06
- C++中#include头文件的示例详解 2023-02-08
- c# – Linq to Sql – 日期时间格式 – YYYY-MMM(2009年3月) 2023-11-23