dateformat-crow
Version:
格式化时间 测试用的 无意义
25 lines (22 loc) • 690 B
JavaScript
module.exports = {
dateFormat
}
// 时间戳 以什么类型拼接年月日 "-" "/" 是否显示时分秒
function dateFormat(time, type, flag) {
var date = new Date();
date.setTime(time);
var year = date.getFullYear();
var month = zero(date.getMonth()+1);
var day = zero(date.getDate());
var hour = zero(date.getHours());
var minute = zero(date.getMinutes());
var second = zero(date.getSeconds());
if (flag) {
return year + type + month + type + day
} else {
return year + type + month + type + day + " " + hour + ":" + minute + ":" + second
}
}
function zero(n) {
return n < 10 ? "0" + n : n
}