Date对象
// 创建date对象
let date = new Date()
let y = date.getFullYear() // 从 Date 对象以四位数字返回年份
let M = date.getMonth() // 从 Date 对象返回月份 (0 ~ 11)
let d = date.getDate() // 从 Date 对象返回一个月中的某一天 (1 ~ 31)
let h = date.getHours() // 返回 Date 对象的小时 (0 ~ 23)
let m = date.getMinutes() // 返回 Date 对象的分钟 (0 ~ 59)
let s = date.getSeconds() // 返回 Date 对象的秒数 (0 ~ 59)
let week = date.getDay() // 从 Date 对象返回一周中的某一天 (0 ~ 6)
let time = date.getTime() // 返回 1970 年 1 月 1 日至今的毫秒数
let fomatDate = date.toLocaleString() // 根据本地时间格式,把 Date 对象转换为字符串
推荐阅读:
扫描二维码,在手机上阅读