JSON, HTML: 2001-07-26T20:52:54Z 这样的时间格式是什么?

JSON, HTML: What is the time format as such called 2001-07-26T20:52:54Z?

像下面这样的日期时间格式叫什么,例如:2001-07-26T20:52:54Z?

以及如何将日期和时间转换为特定格式并转换为 JSON 的字符串?

例如,如果用户输入 7/26/2001 和 20:52:54,我希望将其转换为 2001-07-26T20:52:54Z 格式。

谢谢

它被称为ISO 8601数据格式。

Date:                          2016-08-19
Combined date and time in UTC: 2016-08-19T19:03:01+00:00
                               2016-08-19T19:03:01Z
                               20160819T190301Z
Week:                          2016-W33
Date with week number:         2016-W33-5
Date without year:             --08-19
Ordinal date:                  2016-232

要进行转换,您可以使用 Date#toISOString

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, as denoted by the suffix "Z".

var today = new Date('05 October 2011 14:48 UTC');
console.log(today.toISOString()); // Returns 2011-10-05T14:48:00.000Z123

示例

function convert() {
    var date = document.forms.iso.date.value,
        time = document.forms.iso.time.value,
        dateTime = new Date(date + ' ' + time + ' UTC');
    document.getElementById('iso').innerHTML = dateTime.toISOString();
}
<form name="iso">
    date: <input type="text" name="date" value="7/26/2001"/><br />
    time: <input type="text"name="time" value="20:52:54" /><br />
    <button onclick="convert();">Convert</button>
</form>
<div id="iso"></div>

您可以访问this page。只要您知道该标准的名称并且 google 您应该能够弄清楚其他所有内容。

var d = new Date();
var n = d.toISOString();
n.replace(/\.\d{3}/,"")

2016-09-16T06:38:12Z

叫做ISO 8601 format. If you're using Python simply call isoformat() method, for other languages see following links: C#, Java, JavaScript。无论如何 google 在那里真的很有帮助。