hukuangjie
let getNowFormatDate = () => { //获取当前时间

  let date = new Date();

  let seperator1 = "."; //年月日之间的分隔

  let seperator2 = ":"; //时分秒之间的分隔

  let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; //获取月,如果小于10,前面补个0

  let strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); //获取日,如果小于10,前面补个0

  let strHours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); //获取小时,如果小于10,前面补个0

  let strMinutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); //获取分,如果小于10,前面补个0

  let strSeconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); //获取秒,如果小于10,前面补个0

  let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +

​    " " + strHours + seperator2 + strMinutes +

​    seperator2 + strSeconds; //拼接一下

  return currentdate; //返回

}



let time = getNowFormatDate(); //打印输出:2020.04.02 12:34:56

分类:

技术点:

相关文章:

  • 2021-08-07
  • 2021-08-06
  • 2021-11-29
  • 2021-12-09
  • 2021-11-29
  • 2021-12-05
  • 2021-11-29
  • 2021-12-23
猜你喜欢
  • 2021-08-07
  • 2021-11-24
  • 2021-08-26
  • 2021-08-07
相关资源
相似解决方案