Skip to content

Date

创建日期对象

js
const date = new Date();

常用方法

方法描述示例
new Date()获取日期对象Fri Jun 27 2025 07:25:49 GMT+0000 (Coordinated Universal Time)
getFullYear()获取四位数的年份2025
getMonth()获取月份(0-11,0代表一月,11代表十二月)5
getDate()获取月份中的日(1-31)27
getDay()获取星期几(0-6,0代表星期日,6代表星期六)5
getHours()获取小时数(0-23)7
getMinutes()获取分钟数(0-59)25
getSeconds()获取秒数(0-59)49
getMilliseconds()获取毫秒数(0-999)730
getTime()获取自1970年1月1日以来的毫秒数1751009149730
Date.now()返回当前时间的毫秒数1751009149730
toDateString()将日期部分转换为易读格式,不包括时间Fri Jun 27 2025
toTimeString()将时间部分转换为易读格式07:25:49 GMT+0000 (Coordinated Universal Time)
toLocaleDateString()根据本地时间格式,返回日期部分的字符串6/27/2025
toLocaleTimeString()根据本地时间格式,返回时间部分的字符串7:25:49 AM
toLocaleString()根据本地时间格式,返回日期和时间的字符串6/27/2025, 7:25:49 AM
toISOString()以ISO格式返回字符串2025-06-27T07:25:49.730Z
toJSON()以JSON格式返回日期字符串2025-06-27T07:25:49.730Z
toString()将日期转换为完整的字符串表示Fri Jun 27 2025 07:25:49 GMT+0000 (Coordinated Universal Time)
toUTCString()将日期转换为UTC格式的字符串Fri, 27 Jun 2025 07:25:49 GMT
valueOf()返回日期对象的原始值,即自1970年1月1日以来的毫秒数1751009149730