javascriptjquerydatejs

Is there a way of specifying the format of input of date.js?


I'm using the Date.js library and jQuery. This is my code:

var parsedDate2 = Date.parse(date);
alert(parsedDate2.getTime()/1000);

When I use the date:

12/11/2015 08:00 PM 

It treats it as MM/DD/YYYY ...

But when I use the date:

27/11/2015 08:00 PM

Then it treats it as DD/MM/YYYY ..., which is actually the version that I prefer. So how can I set up the format DD/MM/YYYY ... to use all the time and forget about the MM/DD/YYYY ... ?


Solution

  • The Date.js library you're using is nearly a decade old, and appears to have no recent updates. I would encourage you to instead us something like moment.js, which is thriving and well-supported.

    With moment.js, you can pass the format as the second argument:

    var date = moment( "12/11/2015", "DD-MM-YYYY" );