日期和时间

  1. 获取日期和时间
  2. 访问日期组件
  3. 获取时间戳
  4. 对字符串调用 Date.parse 获取时间戳
  5. 时间差
  6. 设置日期组件

本地格式化

在旧版本浏览器中, locales 和 options 参数被忽略,使用的语言环境和返回的字符串格式是各自独立实现的。

  1. new Date().toDateString():Thu May 16 2024 【注:把 Date 对象的日期部分转换为字符串】
  2. new Date().toISOString():2024-05-16T06:36:56.235Z 【注:使用 ISO 标准返回字符串的日期格式】
  3. new Date().toJSON():2024-05-16T06:37:59.936Z 【注:以 JSON 数据格式返回日期字符串】
  4. new Date().toLocaleTimeString():14:39:43 【注:根据本地时间格式,把 Date 对象的时间部分转换为字符串】
  5. new Date().toLocaleString():2024/5/16 14:40:23 【注:根据本地时间格式,把 Date 对象转换为字符串】
  6. new Date().toString():Thu May 16 2024 14:41:19 GMT+0800 (中国标准时间) 【注:把 Date 对象转换为字符串】
  7. new Date().toTimeString():14:42:03 GMT+0800 (中国标准时间) 【注:把 Date 对象的时间部分转换为字符串】
  8. new Date().toUTCString():Thu, 16 May 2024 06:42:57 GMT 【注:根据世界时,把 Date 对象转换为字符串】
  9. 字符串格式因不同语言而不同。新增的参数 locales 和 options 使程序能够指定使用哪种语言格式化规则,允许定制该方法的表现(behavior)。