baozhengrui

导航

返回年月日

 //返回年月日
    getYTime(time = new Date()) {
      let year = time.getFullYear();
      let month =
        time.getMonth() + 1 > 9 ?
        time.getMonth() + 1 :
        "0" + (time.getMonth() + 1);
      let day = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      let hours = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      let minute =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      let second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      return (
        year +
        "-" +
        month +
        "-" +
        day
      );
    },
    //返回年月日星期
    getTimeData(time = new Date()) {
      let weeks = '日一二三四五六'.split("")
      let year = time.getFullYear();
      let month =
        time.getMonth() + 1 > 9 ?
        time.getMonth() + 1 :
        "0" + (time.getMonth() + 1);
      let day = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      let week = weeks[time.getDay()];
      let hours = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      let minute =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      let second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      return {
        year,
        month,
        day,
        hours,
        minute,
        second,
        week
      }
    },
    //返回小时分秒
    getHTime(time = new Date()){
      let year = time.getFullYear();
      let month =
        time.getMonth() + 1 > 9 ?
        time.getMonth() + 1 :
        "0" + (time.getMonth() + 1);
      let day = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
      let hours = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
      let minute =
        time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
      let second =
        time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
      return (
        hours +
        " : " +
        minute +
        " : " +
        second
      );
    },

posted on 2024-09-10 09:58  芮艺  阅读(4)  评论(0编辑  收藏  举报