I want to convert date to timestamp, my input is 26-02-2012
. I used
new Date(myDate).getTime();
It says NaN.. Can any one tell how to convert this?
I want to convert date to timestamp, my input is 26-02-2012
. I used
new Date(myDate).getTime();
It says NaN.. Can any one tell how to convert this?
To convert (ISO) date to Unix timestamp, I ended up with a timestamp 3 characters longer than needed so my year was somewhere around 50k...
I had to devide it by 1000:
new Date('2012-02-26').getTime() / 1000
There are two problems here. First, you can only call getTime on an instance of the date. You need to wrap new Date in brackets or assign it to variable.
Second, you need to pass it a string in a proper format.
Working example:
this refactored code will do it
this works on all modern browsers except ie8-