日期与时间
静态方法
Date.now()
Date.now() 方法返回自 1970 年 1 月 1 日 00:00:00 (UTC) 到当前时间的毫秒数。
console.log(Date.now()); // 1751251716345Date.parse()
Date.parse() 方法解析一个表示某个日期的字符串,并返回从 1970-1-1 00:00:00 UTC 到该日期对象(该日期对象的 UTC 时间)的毫秒数,如果该字符串无法识别,或者一些情况下,包含了不合法的日期数值(如:2015-02-31),则返回值为 NaN。
console.log(Date.parse('2025-06-29')); //1751155200000Date.UTC()
实例方法
// 根据本地时间,返回一个指定的日期对象为一个月中的哪一日(从 1--31)。
console.log(date.getDate());
// 根据本地时间,返回一个具体日期中一周的第几天,0 表示星期天。对于某个月中的第几天
console.log(date.getDay());
// getFullYear() 方法根据本地时间返回指定日期的年份。此方法替代 getYear()
console.log(date.getFullYear());
// getMonth() 方法根据本地时间,返回一个指定的日期对象的月份,为基于 0 的值(0 表示一年中的第一月)。
console.log(date.getMonth());
// getHours() 方法根据本地时间,返回一个指定的日期对象的小时。
console.log(date.getHours());
// getMinutes() 方法根据本地时间,返回一个指定的日期对象的分钟数。
console.log(date.getMinutes());
// getSeconds() 方法根据本地时间,返回一个指定的日期对象的秒数。
console.log(date.getSeconds());
// getMilliseconds() 方法根据本地时间,返回一个指定的日期对象的毫秒数。
console.log(date.getMilliseconds());
// getTime() 方法返回一个时间的格林威治时间数值。
console.log(date.getTime());
// getTimezoneOffset() 方法返回协调世界时(UTC)相对于当前时区的时间差值,单位为分钟。
console.log(date.getTimezoneOffset());最后更新于
这有帮助吗?