vue中获取当前年月日时分秒
JavaScript 中如何获取当前年月日时分秒
·
let nowDate = new Date();
let date = {
year: nowDate.getFullYear(),
month: nowDate.getMonth() + 1,
date: nowDate.getDate(),
hours: nowDate.getHours(),
minutes: nowDate.getMinutes(),
seconds: nowDate.getSeconds(),
};
let newmonth = date.month > 10 ? date.month : "0" + date.month;
let newday = date.date > 10 ? date.date : "0" + date.date;
let newminutes = date.minutes < 10 ? "0" + date.minutes : date.minutes;
let newseconds = date.seconds < 10 ? "0" + date.seconds : date.seconds;
// 我需要的时间格式为 "yyyy-MM-dd HH:mm:ss" 有不一样的自己拼别的,都是字符串拼接
this.newTime =
date.year +
"-" +
newmonth +
"-" +
newday +
" " +
date.hours +
":" +
newminutes +
":" +
newseconds;
更多推荐
已为社区贡献1条内容
所有评论(0)