Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define format for Date.parse in javascript [duplicate]

I am using Date.parse to convert a string to a date in javascript, however, if the string looks like this '10/11/2016' it is interpreted as Oct 11 2016, i need it to be interpreted as Nov 10 2016

Suggestions?

like image 707
D.B Avatar asked Nov 09 '16 23:11

D.B


People also ask

What date format is DD MMM YYYY JavaScript?

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.

How do I change date format in SimpleDateFormat?

Format date with SimpleDateFormat('MM/dd/yy') in Java // displaying date Format f = new SimpleDateFormat("MM/dd/yy"); String strDate = f. format(new Date()); System. out. println("Current Date = "+strDate);


1 Answers

By default Date.parse consider in this format that month precede the day to be in your case MM/DD/YYYY not as you want DD/MM/YYYY.

I prefer/suggest using 3rd party date parser library as Moment.js

It can take your date-string and the format to be like this:

moment("10/11/2016", "DD-MM-YYYY");
like image 92
Basim Hennawi Avatar answered Oct 14 '22 15:10

Basim Hennawi