js - date

const _date = new Date(); // 新建时间, 或 (new Date);

// 获取
_date.getTime(); // 时间戳, 或 Date.now(); 一个从1970,1,1至今的毫秒
_date.getFullYear(); // 年; _date.getUTCFullYear(), 国际标准时间
_date.getMonth(); // 月, [0, 11]
_date.getDate(); // 日
_date.getDay(); // 周, [0, 6]
_date.getHours(); // 时
_date.getMinutes(); // 分
_date.getSeconds(); // 秒
_date.getMilliseconds(); // 毫秒

// 设置
_date.setDate(6); // 将以上get改成set
new Date(2018, 0, 2); // 表示1月2号 或 new Date('jan 2, 2018');

Date.now() - new Date(2018, 0, 1); // 常用计算, 返回时间戳

猜你喜欢

转载自blog.csdn.net/NaShiShiWo/article/details/85598691