Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain utc time in jQuery datetimepicker

I am using the trying this jQuery datetimepicker to obtain date and time data. I am able to get most of the things out (format, display, etc). However, I wasn't able to get the date and time in UTC format. I am only able to obtain the date and time in local format.

Does anyone know how to modify it to get the date and time? or remove off the "Now" button in the popup?

like image 649
user1599647 Avatar asked Aug 15 '12 03:08

user1599647


People also ask

What is the default value of DatePicker?

By default, the DatePicker value is null and the Calendar popup is hidden.

What is date picker and time picker?

A date picker, popup calendar, date and time picker, or time picker is a graphical user interface widget which allows the user to select a date from a calendar and/or time from a time range.

What is DatePicker in jQuery?

A date-picker of jQuery UI is used to provide a calendar to the user to select the date from a Calendar. This date picker usually connected to a text-box so user selection of date from the calendar can be transferred to the textbox.


1 Answers

I ran into the same issue today, and found this old thread. You can override $.datepicker._gotoToday to use UTC Time when you click the "now" button.

//make the now button go to "now" in utc, not local
$.datepicker._gotoToday = function(id) {
  var inst = this._getInst($(id)[0]),
      $dp = inst.dpDiv;
  this._base_gotoToday(id);
  var tp_inst = this._get(inst, 'timepicker');
  //removed -> selectLocalTimeZone(tp_inst);
  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();
};
like image 112
user1787024 Avatar answered Sep 23 '22 22:09

user1787024