当前位置:   article > 正文

js获取当前年月入_js 获取当前年月

js 获取当前年月

const nowTime = new Date();

// 获取当前时间的年、月、日、时、分、秒
const year = nowTime.getFullYear();
const month = nowTime.getMonth() + 1; // 月份从0开始,所以需要加1
const day = nowTime.getDate();
const hours = nowTime.getHours();
const minutes = nowTime.getMinutes();
const seconds = nowTime.getSeconds();
// 格式化时间字符串
const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号