Get String in YYYYMMDD format from JS date object?

后端 未结 30 1774
一个人的身影
一个人的身影 2020-11-22 10:47

I\'m trying to use JS to turn a date object into a string in YYYYMMDD format. Is there an easier way than concatenating Date.getYear()

30条回答
  •  囚心锁ツ
    2020-11-22 11:44

    var someDate = new Date();
    var dateFormated = someDate.toISOString().substr(0,10);
    
    console.log(dateFormated);

提交回复
热议问题