I am trying to convert "July 24 2013" to "DD-MM-YYYY" with javascript but I keep getting and error.
I am using new Date('July 24 2013').format("DD-MM-YYYY");
What am I missing?
There is no native format in JavaScript for” dd-mmm-yyyy”. To get the date format “dd-mmm-yyyy”, we are going to use regular expression in JavaScript.
const d = new Date("2015-3-25"); The behavior of "YYYY/MM/DD" is undefined.
toISOString() The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long ( YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss. sssZ , respectively).
Date
object doesn't have .format()
method.
If you work with date and time actively I'd recommend you to use MomentJS library then.
It has a lot of useful functionality to work with time and date.
For example: moment('July 24 2013', 'MMMM D YYYY').format('MMMM D YYYY, h:mm:ss a');
I would highly advise using momentjs!
moment('July 24 2013').format("DD-MM-YYYY");
// => "24-07-2013"
Simple as that!
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