js获取指定时间

// 获取当前时间
    getNowTime(stime, flag) {
      let dateo = stime ? new Date(stime) : new Date();
      let dateTime;
      let yy = dateo.getFullYear();
      let mm = dateo.getMonth() + 1;
      let dd = dateo.getDate();
      let hh = dateo.getHours();
      let mf =
        dateo.getMinutes() < 10 ? "0" + dateo.getMinutes() : dateo.getMinutes();
      let ss =
        dateo.getSeconds() < 10 ? "0" + dateo.getSeconds() : dateo.getSeconds();
      if (flag) {
        dateTime = yy + "" + mm + "" + dd;
      }else{
        dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
      }
      // console.log(dateTime);
      return dateTime;
    },

你可能感兴趣的:(前端javascript)