Obtenez l'heure, la minute et la seconde de l'heure actuelle, le premier jour du mois et le dernier jour

//安装时间格式化插件
npm install  moment 
<script>
import moment from 'moment'
const getTime = () => {
      
      
  const now = new Date(); // 当前日期
  const nowYear = now.getFullYear(); //当前年
  const nowMonth = now.getMonth(); //当前月 (值为0~11)
  const d = now.getDate(); //当天
  const firstDay = new Date(nowYear, nowMonth, 1, 0, 0); // 本月开始时间
  const LastDay = new Date(nowYear, nowMonth + 1, 0, 23, 59); // 本月结束时间
  const toDay = new Date(nowYear, nowMonth, d); // 本月今天
  //如果想获取本月第一天00:00和最后一天23:59
  //const firstDay = new Date(nowYear,nowMonth,1,00,00)
  //const LastDay = new Date(nowYear, nowMonth+1,0, 23,59);
  //const toDay = new Date(nowYear, nowMonth, d, 23,59,59); // 获取今天23时:59分:59秒
};
//此时获取的是标准时间,时间格式化为YY-MM-DD HH:mm:ss
 console.log(moment(firstDay).format('YY-MM-DD HH:mm:ss'));//加入是12月,2022-12-1 00:00:00
</script>

Guess you like

Origin blog.csdn.net/qq_42859450/article/details/128093459