Javascript date how to convert 'dd-MMMM-yyyy' format in timestamp?

I’ve got the current date from a datepicker widget in this format

dd-MMMM-yyyy

but all in all it could be a better format dd MMMM yyyy if possible

how to convert it in timestamp ?

I could map the month but it’s quite ugly ^^

Hi there,

Could you give me an example of what you have (e.g. "01-01-14) and what you want (e.g. “01 January 2014”)

Sorry if this is obvious, I’m having a slow day :slight_smile:

I’ve got

26-January-2014

I want a timestamp like

1390690800000

possible with the right timezone

I found https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
but it doesn’t work with that format :frowning:

or
new Date(“26 January 2014”).getTime()

Hi,

Just do this:

var date = new Date("26-January-2014"),
    timestamp = +date;

console.log(timestamp);
=>1390690800000

var date = new Date("26-January-2014");
+date;

give me NaN

Shouldn’t do.

What does the following command give you:

console.log(Number(new Date("26-January-2014")));

Take a closer look Pullo’s code again. You didn’t replicate the syntax properly.

it’s simply a shortcut :slight_smile:

I found the tricky point
may be or sure my ff version it’s buggy
in the console also

Number(new Date("26-January-2014"))

give me NaN
I tried it in the chrome console and it works
thanks for the snippet

Hi,

It’s the hyphens in the date that FF is balking at, Chrome seems to accept them for some reason.

This will work in FF, too:

var date = new Date(("26-January-2014").replace(/-/g, " "));
+date