Search code examples
jquerydatepickerjquery-ui-datepickerdatetimepickertimepicker

How to set 'Now' button on jquery UI datetimepicker to set UTC time?


I'm using the datetimepicker here. How can I set the now button so that it sets time UTC now instead of the current now per browser?


Solution

  • This worked for setting the time but not so much for setting the actual date on the calendar.

    $.datepicker._gotoToday = function (id) {
        var inst = this._getInst($(id)[0]),
        $dp = inst.dpDiv;
        this._base_gotoToday(id);
        var tp_inst = this._get(inst, 'timepicker');
        var now = new Date();
        var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
        this._setTime(inst, now_utc);
        $('.ui-datepicker-today', $dp).click();
    };