node.js 日期格式化

来源:互联网 发布:易宠软件 登录 编辑:程序博客网 时间:2024/06/05 07:08
function fix2number(n) {    return [0,n].join('').slice(-2);}function getTime(format) {    var curDate = new Date();    if (format == undefined) return curDate;    format = format.replace(/Y/i, curdate.getFullYear());    format = format.replace(/m/i, fix2number(curdate.getMonth() + 1));    format = format.replace(/d/i, fix2number(curdate.getDate()));    format = format.replace(/H/i, fix2number(curdate.getHours()));    format = format.replace(/i/i, fix2number(curdate.getMinutes()));    format = format.replace(/s/i, fix2number(curdate.getSeconds()));    format = format.replace(/ms/i, curdate.getMilliseconds());    return format;}

0 0
原创粉丝点击