moment日期处理类库
Moment 被设计为在浏览器和 Node.js 中都能工作。
安装
npm install moment --save # npm
yarn add moment # Yarn
使用
/** * Features: 时间日期格式化工具 * official website docs: http://momentjs.cn/docs/#/i18n/ */ import moment from 'moment'; let time = { getDateTime: function (dateTime) { return moment(dateTime, 'YYYY-MM-DD HH:mm:ss'); }, getTime: function (dateTime) { return moment(dateTime, 'HH:mm:ss'); }, parseDateTime: function (dateTime) { return moment(dateTime).format('YYYY-MM-DD HH:mm:ss'); }, parseDateTimeNoS: function (dateTime) { return moment(dateTime).format('YYYY-MM-DD HH:mm'); }, parseTime: function (dateTime) { return moment(dateTime).format('HH:mm:ss'); }, getCustomTime: function (formatStr, dateTime) { return moment(dateTime, formatStr); }, parseCustomTime: function (formatStr, dateTime) { return moment(dateTime).format(formatStr); }, //时间转换时间戳 transToTimeStamp: function(date) { if(date){ return Math.round(new Date(date).getTime() / 1000); } return undefined; }, utcTimeList: [ { id: "0", name: "GMT-12:00", key: "GMT-12:00" }, { id: "1", name: "GMT-11:00", key: "GMT-11:00" }, { id: "2", name: "GMT-10:00", key: "GMT-10:00" }, { id: "3", name: "GMT-09:30", key: "GMT-09:30" }, { id: "4", name: "GMT-09:00", key: "GMT-09:00" }, { id: "5", name: "GMT-08:00", key: "GMT-08:00" }, { id: "6", name: "GMT-07:00", key: "GMT-07:00" }, { id: "7", name: "GMT-06:00", key: "GMT-06:00" }, { id: "8", name: "GMT-05:00", key: "GMT-05:00" }, { id: "9", name: "GMT-04:30", key: "GMT-04:30" }, { id: "10", name: "GMT-04:00", key: "GMT-04:00" }, { id: "11", name: "GMT-03:30", key: "GMT-03:30" }, { id: "12", name: "GMT-03:00", key: "GMT-03:00" }, { id: "13", name: "GMT-02:30", key: "GMT-02:30" }, { id: "14", name: "GMT-02:00", key: "GMT-02:00" }, { id: "15", name: "GMT-01:00", key: "GMT-01:00" }, { id: "16", name: "GMT+00:00", key: "GMT+00:00" }, { id: "17", name: "GMT+01:00", key: "GMT+01:00" }, { id: "18", name: "GMT+02:00", key: "GMT+02:00" }, { id: "19", name: "GMT+03:00", key: "GMT+03:00" }, { id: "20", name: "GMT+03:30", key: "GMT+03:30" }, { id: "21", name: "GMT+04:00", key: "GMT+04:00" }, { id: "22", name: "GMT+04:30", key: "GMT+04:30" }, { id: "23", name: "GMT+05:00", key: "GMT+05:00" }, { id: "24", name: "GMT+05:30", key: "GMT+05:30" }, { id: "25", name: "GMT+05:45", key: "GMT+05:45" }, { id: "26", name: "GMT+06:00", key: "GMT+06:00" }, { id: "27", name: "GMT+06:30", key: "GMT+06:30" }, { id: "28", name: "GMT+07:00", key: "GMT+07:00" }, { id: "29", name: "GMT+08:00", key: "GMT+08:00" }, { id: "30", name: "GMT+08:45", key: "GMT+08:45" }, { id: "31", name: "GMT+09:00", key: "GMT+09:00" }, { id: "32", name: "GMT+09:30", key: "GMT+09:30" }, { id: "33", name: "GMT+10:00", key: "GMT+10:00" }, { id: "34", name: "GMT+10:30", key: "GMT+10:30" }, { id: "35", name: "GMT+11:00", key: "GMT+11:00" }, { id: "36", name: "GMT+11:30", key: "GMT+11:30" }, { id: "37", name: "GMT+12:00", key: "GMT+12:00" }, { id: "38", name: "GMT+12:45", key: "GMT+12:45" }, { id: "39", name: "GMT+13:00", key: "GMT+13:00" }, { id: "40", name: "GMT+14:00", key: "GMT+14:00" } ] } export default time; export const getDateTime = time.getDateTime; export const getTime = time.getTime; export const parseDateTime = time.parseDateTime; export const parseDateTimeNoS = time.parseDateTimeNoS; export const parseTime = time.parseTime; export const parseCustomTime = time.parseCustomTime; export const getCustomTime = time.getCustomTime; export const transToTimeStamp = time.transToTimeStamp;
延伸:时间
https://www.debugger.wiki/article/html/1611858960268257
信息创造价值, 知识就是力量。