Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  114] [ 5]  / answers: 1 / hits: 16272  / 7 Years ago, mon, april 10, 2017, 12:00:00

Basically I have a Date object. How can convert it to a string compatile with datetime-local format yyyy-MM-ddThh:mm?



I tried Date.toISOString method, but it doesn't work as it appends .SSSZ at the end. Gives me the following output The specified value 2017-04-10T17:02:00.320Z does not conform to the required format. The format is yyyy-MM-ddThh:mm followed by optional :ss or :ss.SSS..



Does anyone have any clean solution to this problem?


More From » javascript

 Answers
51

I used moment.js library to format the date accordingly. This line of code does the trick moment(date).format(YYYY-MM-DDTkk:mm).


[#58199] Friday, April 7, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeffery

Total Points: 180
Total Questions: 114
Total Answers: 117

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;