Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Datetime picker to UTC time

I am trying to standardise the time the database gets from a the bootstrap time date form, however I am getting the following error

Uncaught TypeError: e.date.getTime is not a function

When I print out e.date it is Wed Jul 15 2015 16:30:51 GMT+1200

I am attempting to follow this guide, but I have had to change a few things to get this far.http://jsfiddle.net/TC6Gr/37/

$('#start_time').datetimepicker({
    format: 'DD-MM-YYYY h:mm:ss a',
}).on("dp.change", function (e) {
    alert(e.date);
    $('#start-time-before').html(e.date); // Log
    var TimeZoned = new Date(e.date.setTime(e.date.getTime() + (e.date.getTimezoneOffset() * 60000)));
    $('#end_time').datetimepicker('setStartDate', TimeZoned);
    $('#start_time').datetimepicker('setDate', TimeZoned);
    $('#start-time-adjusted').html(TimeZoned); // Log
});
like image 238
Matt Ellwood Avatar asked Jul 08 '15 04:07

Matt Ellwood


1 Answers

Use this line

new Date("2018/10/10 09:27");

This can create a Date object. You will return Date object's getTime() or valueOf() functions with the UTC timestamp.

like image 52
Future Coder Avatar answered Oct 15 '22 16:10

Future Coder