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?
Convert timestamp to date If you have a list of timestamp needed to convert to date, you can do as below steps: 1. In a blank cell next to your timestamp list and type this formula =(((A1/60)/60)/24)+DATE(1970,1,1), press Enter key, then drag the auto fill handle to a range you need.
Split the string into its parts and provide them directly to the Date constructor:
Update:
var myDate = "26-02-2012"; myDate = myDate.split("-"); var newDate = new Date( myDate[2], myDate[1] - 1, myDate[0]); console.log(newDate.getTime());
Try this function, it uses the Date.parse() method and doesn't require any custom logic:
function toTimestamp(strDate){ var datum = Date.parse(strDate); return datum/1000; } alert(toTimestamp('02/13/2009 23:31:30'));
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