编程语言
首页 > 编程语言> > javascript——获取当前日期

javascript——获取当前日期

作者:互联网

2021-09-09

let date = new Date();
    let seperator1 = "-";
    let year = date.getFullYear();
    let month: any = date.getMonth() + 1;
    let strDate: any = date.getDate();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    let endTime = year + seperator1 + month + seperator1 + strDate;

标签:09,seperator1,javascript,strDate,month,获取,日期,let,date
来源: https://blog.csdn.net/Willow_Spring/article/details/120207522