index.js 622 Bytes
Newer Older
Scott Sun's avatar
Scott Sun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

var moment = require('moment')
print(moment().format("YYYY-MM-DD HH:mm:ss"))

// 加
print(moment().add(1,'months').format("YYYY-MM-DD HH:mm:ss"))
// 减
print(moment().subtract(7,'days').format("YYYY-MM-DD HH:mm:ss"))

// 获取星期几
print(moment().day())

// 毫秒数
print(moment().valueOf())

// 获取时间差(以毫秒计算)
var endTime = new Date(2020,0,1).getTime()
print(moment(endTime).diff(moment(Date.now()),'days'))

// 时间转化

var times = 12783124
print(moment.duration(times).hours()+"小时")
print(moment.duration(times).minutes()+"分钟")
print(moment.duration(times).seconds()+"秒")