Saturday, 27 December 2014

Convert Date to Milliseconds in javascript

// convert date time to milli seconds; date is in the format of dd/mm/yyyy hh:mm a;
function convertDateTime(date){
var O_dateParts = date.split(' ');
var hours;
if(O_dateParts[2] == "AM" && parseInt(O_dateParts[1].split(':')[0]) == 12) hours = 0;
else if(O_dateParts[2] == "AM") hours = O_dateParts[1].split(':')[0];
else if(O_dateParts[2] == "PM") hours = parseInt(O_dateParts[1].split(':')[0]) + 12;
return (new Date(O_dateParts[0].split('/')[2],parseInt(O_dateParts[0].split('/')[1])-1,O_dateParts[0].split('/')[0],hours,O_dateParts[1].split(':')[1])).getTime();
}

No comments:

Post a Comment