Reputation: 295
I have:
(new Date()).toISOString().slice(0, 10)
I want it returns without UTC:
2013-08-31
I try:
new Date().getYear() + "-" + new Date().getMonth() + "-" + new Date().getDay()
But it does not work. It returns: 113-7-6.
Thanks a lot.
Upvotes: 0
Views: 47
Reputation: 359776
Date.getYear()
returns the year (usually 2-3 digits) in the specified date according to local time, and is deprecated. Use Date.getFullYear()
instead.Date.getMonth()
returns a zero-indexed value, so you need to add 1
to get 8
.Date.getDay()
returns zero-indexed day of the week. Use Date.getDate()
instead to get 31
.You'll need to zero-pad 8
to get a string with 08
in it, by the way. Or you could simplify everything and use a date formatting library – you'll still need to read documentation, though.
Recommended reading:
Date
documentationUpvotes: 1