Get String in YYYYMMDD format from JS date object?

后端 未结 30 2275
一个人的身影
一个人的身影 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:47

    If you don't mind including an additional (but small) library, Sugar.js provides lots of nice functionality for working with dates in JavaScript. To format a date, use the format function:

    new Date().format("{yyyy}{MM}{dd}")
    

提交回复
热议问题