1
I’m using the datetimepicker
Bootstrap and need to convert the result to "milliseconds".
Currently the result comes out: "dd/mm/yyyy - hh:ss" and I need it in "milliseconds".
What’s the best way?
1
I’m using the datetimepicker
Bootstrap and need to convert the result to "milliseconds".
Currently the result comes out: "dd/mm/yyyy - hh:ss" and I need it in "milliseconds".
What’s the best way?
3
Just use the method getDate
, or any of the events, such as changeDate
, to recover in format Date
, instead of taking the string formatted.
Then just apply the .getTime()
:
$('#time').datetimepicker().on('changeDate', function (e) {
// Aqui você tem o resultado em ms sem precisar fazer o parse manual:
e.date.getTime();
});
See working on JS Fiddle.
1
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();
Browser other questions tagged javascript jquery
You are not signed in. Login or sign up in order to post.