gpt4 book ai didi

javascript - 正确的 Javascript Date.parse(...) 格式字符串?

转载 作者:行者123 更新时间:2023-12-03 03:21:56 25 4
gpt4 key购买 nike

构造字符串的文化不变方式是什么,以便 Javascript Date() 构造函数可以解析它并创建正确的日期对象?

我尝试过这些不起作用的格式字符串(使用 C# 生成字符串):

clientDate.ToString();
// gives: "11/05/2009 17:35:23 +00:00"

clientDate.ToString("MMM' 'dd', 'yyyy' 'h':'mm':'ss' 'tt");
// works on an English server
// but on a French server, gives: "mai 11, 2009 5:35:23"
// Javascript won't parse that.

clientDate.ToString("MM'-'dd'-'yyyy' 'HH':'mm':'ss")
// gives: 05-11-2009 17:35:23

什么是通用格式?

最佳答案

According to MDC :

Given a string representing a time, parse returns the time value. It accepts the IETF standard (RFC 1123 Section 5.2.14 and elsewhere) date syntax: "Mon, 25 Dec 1995 13:30:00 GMT". It understands the continental US time-zone abbreviations, but for general use, use a time-zone offset, for example, "Mon, 25 Dec 1995 13:30:00 GMT+0430" (4 hours, 30 minutes east of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent.

如果您无法使用英语语言环境生成此格式,请尝试使用 Date.UTC

关于javascript - 正确的 Javascript Date.parse(...) 格式字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1088793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com