// 创建一个新的 Date 对象,表示当前日期和时间
let currentDate = new Date();
console.log(currentDate); // 输出类似: 2023-10-05T00:00:00.000Z
// 创建一个指定日期的 Date 对象 (年, 月, 日, 时, 分, 秒, 毫秒)
// 注意:月份是从 0 开始计数的,0 表示 1 月,11 表示 12 月
let specificDate = new Date(2023, 9, 5, 12, 30, 0);
console.log(specificDate); // 输出类似: 2023-10-05T04:30:00.000Z
// 使用日期字符串创建 Date 对象
let dateString = new Date('2023-10-05');
console.log(dateString); // 输出类似: 2023-10-05T00:00:00.000Z
// 使用时间戳(自 1970 年 1 月 1 日以来的毫秒数)创建 Date 对象
let timestamp = new Date(1696473600000);
console.log(timestamp); // 输出类似: 2023-10-05T00:00:00.000Z
new Date()
:创建一个表示当前日期和时间的 Date
对象。new Date(year, month, day, hours, minutes, seconds, milliseconds)
:创建一个指定日期和时间的 Date
对象。注意月份是从 0 开始的。new Date(dateString)
:使用日期字符串创建 Date
对象。常见的格式包括 ISO 8601 格式(如 '2023-10-05'
)。new Date(timestamp)
:使用时间戳(自 1970 年 1 月 1 日以来的毫秒数)创建 Date
对象。下一篇:js array length
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站