$9.88

Get String in YYYYMMDD format from JS date object?

Ask a question+
4

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

1

You can use Intl object.
example:

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
5

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

Vazgen Manukyan 610
add comment

Your Answer