I'm using Bootstrap's datetimepicker
f and need to convert the result to milliseconds.
Currently the result is: "dd / mm / yyyy - hh: ss" and need it in "milliseconds".
What's the best way?
I'm using Bootstrap's datetimepicker
f and need to convert the result to milliseconds.
Currently the result is: "dd / mm / yyyy - hh: ss" and need it in "milliseconds".
What's the best way?
Just use the getDate
method, or any of the events, such as changeDate
, to retrieve in Date
format instead of taking the formatted string.
Then, just apply .getTime()
:
$('#time').datetimepicker().on('changeDate', function (e) {
// Aqui você tem o resultado em ms sem precisar fazer o parse manual:
e.date.getTime();
});
Watch working on JS Fiddle .
var dateString = $('21/09/2014 - 18:22'),
dateArgs = dateString.match(/\d{2,4}/g),
year = dateArgs[2],
month = dateArgs[1],
day = dateArgs[0],
hour = dateArgs[3],
minutes = dateArgs[4];
milliseconds = new Date(year, month, day, hour, minutes).getTime();