Reputation: 43
I need to generate a date in UTC format, but without the time part, that is, instead of getting:
Wed, 19 Jan 2021 19:27:00 GMT
I need only:
Wed, 19 Jan 2021
I know that there is a "long" way to do it by formatting the string myself using methods one instance of Date()
and concatenating them. But I would like to know if there is a shorter way to do it.
By the way, I can only use Javascript vanilla.
Upvotes: 0
Views: 1160
Reputation: 519
I don't know what you mean by long but the code for extracting only the part you're looking for is pretty short.
'Wed, 19 Jan 2021 19:27:00 GMT'.split(' ').slice(0, -2)
Edit: If you really dislike this code I just found out that Date.toDateString() exists
Upvotes: 1