1
0
Files
frost-zx.github.io/docs/content/description-date-time-string-format.md
2025-10-13 10:20:34 +08:00

65 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "包含 T 和 Z 的日期时间字符串格式"
date: 2025-03-15T23:11:02Z
lastmod: 2025-03-15T23:11:27Z
tags: [格式,时间,日期]
---
# 包含 T 和 Z 的日期时间字符串格式
ECMAScript 基于 ISO 8601 扩展格式的简化定义了日期时间的字符串交换格式。
格式为:`YYYY-MM-DDTHH:mm:ss.sssZ`
|内容|描述|
| :-----| :-------------------------------------------------------------------|
|YYYY|公历中 0000 到 9999 年的十进制数字。|
|-|“-”(连字符)在字符串中出现两次,分隔年、月、日。|
|MM|一年中的月份,从 01一月到 12十二月。|
|DD|月份中的天数,从 01第一天到 31最后一天。|
|T|表示字符串中的时间部分的开始。|
|HH|自午夜以来经过的完整小时数,从 00 到 24 的两位十进制数字。|
|:|“:”(冒号)在字符串中出现两次,分隔时、分、秒。|
|mm|当前小时经过的完整分钟数,从 00 到 59 的两位十进制数字。|
|ss|当前分钟经过的完整秒数,从 00 到 59 的两位十进制数字。|
|.|“.”(点)在字符串中出现一次,分隔秒、毫秒。|
|sss|当前秒经过的完整毫秒数,从 000 到 999 的三位十进制数字。|
|Z|时区,使用 “Z” 表示 UTC或使用 “+”、“-”,并在后方跟随 HH:mm|
||格式的时间表达式表示偏移量(例如 `+0800` 表示 +8 小时)。|
所有数字必须为**十进制**形式。
如果 `MM``DD` 字段不存在,则使用默认值 “01”。
如果 `HH`​、`mm``ss` 字段不存在,则使用默认值 “00”。
`sss` 字段不存在,则使用默认值 “000”。
如果没有指定时区,则把字符串作为**本地时间**进行解析。
由于每天都以午夜开始和结束,所以可以在时间表达式中使用 `00:00``24:00` 来区分相同时间点的两个午夜。
也就是说,字符串 `1995-02-04T24:00``1995-02-05T00:00` 可以表示完全相同的时间点。
字符串中可以只包含日期:
```
YYYY
YYYY-MM
YYYY-MM-DD
```
字符串中可以只包含时间:
```
THH:mm
THH:mm:ss
THH:mm:ss.sss
```
参考资料:
- [ECMAScript 2015 Language Specification Date Time String Format](https://262.ecma-international.org/6.0/#sec-date-time-string-format)
- [rfc2822 - Date and Time Specification](https://datatracker.ietf.org/doc/html/rfc2822#section-3.3)