Get String in YYYYMMDD format from JS date object?

Ask a question+

I’m trying to use JS to turn a date object into a string in YYYYMMDD format. I want to find an easier way than concatenating Date.getYear(), Date.getMonth() and Date.getDay()? Is there?

Jane Moore 210
add comment

2 Answers


You can use Intl object.

new Intl.DateTimeFormat('en-US').format(YOUR_DATE_OBJECT);

it can return in any requested locale and any format.

see more about Intl.DateTimeFormat in MDN

add comment

There is a popular library momentjs with works with date and time.

Vazgen Manukyan 610
add comment

Your Answer