trentrichardson / jQuery-Timepicker-Addon

Adds a timepicker to jQueryUI Datepicker
http://trentrichardson.com/examples/timepicker/
MIT License
2.66k stars 1.05k forks source link

Is possible to add five hours to a date and time but get formatted #765

Open montes2012 opened 9 years ago

montes2012 commented 9 years ago

Is possible to add five hours to a date and time but get formatted

$('#fecha_emision').datetimepicker({
  dateFormat: 'yy/mm/dd',
  timeFormat: 'HH:mm',
});
ganna-shmatova commented 9 years ago

I did something similar to translate all input dates to UTC time (so it would add the timezone offset)

options:

var datetime = {
    dateFormat: 'yy/mm/dd',
    timeFormat: 'HH:mm:ss',
    timezone: -420, //utc
    //translates 'now' time to utc
    onSelect: function(text, datepicker){
        var now = new Date(text);
        //convert user's selected time to UTC time
        now = new Date(now.getTime() + now.getTimezoneOffset()*60*1000); //minutes*60seconds*1000milliseconds
        if(datepicker.input)
            datepicker.input.datetimepicker('setDate', now);
    }
};