"DD / MM / YYYY - HH: SS" to "milliseconds"

1

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?

    
asked by anonymous 04.10.2014 / 23:24

2 answers

3

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 .

    
05.10.2014 / 01:50
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();
    
05.10.2014 / 00:27