JavaScript Date对象转时间

Vue.prototype.showTime = function (d) {
let year;
let month;
let date;
let hour;
let minute;
let second;
let nowtime;
if(d){
nowtime = new Date(d);
}else {
nowtime = new Date();//没有传入date 就按现在的时间
}
year = nowtime.getFullYear();
month = nowtime.getMonth() + 1;
date = nowtime.getDate();
hour = nowtime.getHours();
if (hour < 10) {
hour = "0" + hour;
}
minute = nowtime.getMinutes();
if (minute < 10) {
minute = "0" + minute;
}
second = nowtime.getSeconds();
if (second < 10) {
second = "0" + second;
}
let nowTime = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
return nowTime;
};
版权声明:
作者:东明兄
链接:https://blog.crazyming.com/note/616/
来源:CrazyMing
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
海报
JavaScript Date对象转时间
Vue.prototype.showTime = function (d) {
let year;
let month;
let date;
let hour;
let minute;
let second;
let nowtime;
……


共有 0 条评论