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?
JavaScript Date toString() The toString() method returns a date object as a string.
If you instead want to get the current time stamp, you can create a new Date object and use the getTime() method. const currentDate = new Date(); const timestamp = currentDate. getTime(); In JavaScript, a time stamp is the number of milliseconds that have passed since January 1, 1970.
DD/MM/YYYY. MM/DD/YYYY.
The difference between the two is that the datetime-local input does not include the time zone. If the time zone is not important to your application, use datetime-local. Some browsers are still trying to catch up to the datetime input type.
I used moment.js library to format the date accordingly. This line of code does the trick moment(date).format("YYYY-MM-DDTkk:mm")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With