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()
date object
YYYYMMDD
Date.getYear()
Use padStart:
Date.prototype.yyyymmdd = function() { return [ this.getFullYear(), (this.getMonth()+1).toString().padStart(2, '0'), // getMonth() is zero-based this.getDate().toString().padStart(2, '0') ].join('-'); };