Desired return value should be a string formatted as dd-mm-yyyy
.
Im trying to give a format date dd-mm-yyyy to ISOString and adding GMT but the code gives me this format. How can i do?
new Date().toISOString()
.replace(/T/, ' '). // replace T with a space
.replace(/\..+/, ''); // delete the dot and everything after
'2012-11-04 14:55:45'
Use the Date() constructor to convert a string to a Date object, e.g. const date = new Date('2022-09-24') . The Date() constructor takes a valid date string as a parameter and returns a Date object. Copied! We used the Date() constructor to convert a string to a Date object.
Example: Convert Date to Number The new Date() gives the current date and time. To convert the name to a number, we use the getTime() method. The getTime() method returns the number of milliseconds from midnight of January 1, 1970 (EcmaScript epoch) to the specified date.
For your example '2012-11-04 14:55:45'
You can do: new Date('2012-11-04 14:55:45').toISOString().split('T')[0]
in a single line :)
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