Use the moment plugin to get the year, month, day, hour, minute, and second of the timestamp respectively

You can use various methods in the moment plugin to get the year, month, day, hour, minute, and second of the timestamp, for example:

// 假设时间戳为 timestamp = 1629505035000

// 获取年份
moment(timestamp).year(); // 返回 2021

// 获取月份(注意:月份从0开始计数)
moment(timestamp).month(); // 返回 7

// 获取日
moment(timestamp).date(); // 返回 21

// 获取小时
moment(timestamp).hour(); // 返回 16

// 获取分钟
moment(timestamp).minute(); // 返回 43

// 获取秒数
moment(timestamp).second(); // 返回 55

Note: You need to convert the timestamp into a moment object first, and then use the corresponding method to obtain the time information.

Guess you like

Origin blog.csdn.net/u012632105/article/details/132740147