Date.prototype.toTimeString()
Date 实例的 toTimeString() 方法返回一个字符串,表示在本地时区中解释的该日期的时间部分。
¥The toTimeString() method of Date instances returns a string representing the time portion of this date interpreted in the local timezone.
Try it
语法
参数
返回值
描述
¥Description
Date 个实例指的是特定时间点。toTimeString() 解释本地时区的日期并以英语格式化时间部分。它始终使用 hh:mm:ss GMT±xxxx (TZ) 的格式,其中:
¥Date instances refer to a specific point in time. toTimeString() interprets the date in the local timezone and formats the time part in English. It always uses the format of hh:mm:ss GMT±xxxx (TZ), where:
| 格式化字符串 | 描述 | 
|---|---|
hh | 
      小时,如果需要,为带前导零的两位数字 | 
mm | 
      分钟,如果需要,为带前导零的两位数字 | 
ss | 
      秒,如果需要,为带前导零的两位数字 | 
±xxxx | 
      当地时区的偏移量 — 两位数表示小时,两位数表示分钟(例如 -0500、+0800) | 
    
TZ | 
      时区名称(例如 PDT、PST) | 
    
例如:"04:42:04 GMT+0000(协调世界时)"。
¥For example: "04:42:04 GMT+0000 (Coordinated Universal Time)".
- 如果只想获取日期部分,请使用 
toDateString()。 - 如果你想同时获取日期和时间,请使用 
toString()。 - 如果要将日期解释为 UTC 而不是本地时区,请使用 
toUTCString()。 - 如果你想以更用户友好的格式(例如本地化)设置日期格式,请使用 
toLocaleTimeString()。 
示例
使用 toTimeString()
规范
| Specification | 
|---|
| ECMAScript Language Specification  # sec-date.prototype.totimestring  | 
浏览器兼容性
BCD tables only load in the browser