datetimepicker getDate to return Date / Time in UTC format

浪尽此生 提交于 2019-12-01 17:11:36

问题


I happen to read this datetimepicker addon and found it to be of great use. The issue that I am facing using this tool is that I am unable to get data / time format in UTC or other formats (my intention is to at least get date / time in UTC format:

$('#starttime').datetimepicker({
    ampm: true,
    showHour: true,
    showMinute: true,
    showSecond: false,
    showMillisec: false,
    timeFormat: 'hh:mm TT',
    hourGrid: 4,
    stepHour: 1,
    minDate: minDate,
    maxDate: maxDate,
    stepMinute: 10
 });                             

The below script prints me data / time in below format:

var startDt = $('#starttime').datetimepicker('getDate');

Tue May 01 2012 00:00:00 GMT+0530 (India Standard Time)

How can I change this format to any other like

DD-MM-YYYY or DD/MM/YYYY or in UTC format?


回答1:


Demo: http://jsfiddle.net/Dgnjn/2/

or

dd-mm-yy here http://jsfiddle.net/Dgnjn/5/

Now using datetimepicker

The important thing to note in the sample below is:

dateAsObject = $.datepicker.formatDate('mm-dd-yy', new Date(dateAsObject))

code

$('#datetimepicker').datetimepicker({
    //altField: '#alternate',
    dateFormat: 'yy-mm-dd',
    timeFormat: 'hh:mm:ss',
    stepHour: 2,
    stepMinute: 10,
    onSelect: function(dateText, inst) { 
      var dateAsString = dateText; //the first parameter of this function
      var dateAsObject = $(this).datepicker( 'getDate' ); //the getDate method
     dateAsObject = $.datepicker.formatDate('mm-dd-yy', new Date(dateAsObject))
        $('#alternate').val(dateAsObject);
       // alert(dateAsObject + '==> ' + $('#alternate').val());
   }

});



回答2:


These are some of the date formats: http://jqueryui.com/demos/datepicker/#date-formats

$('#starttime').datetimepicker( "option", "dateFormat", "dd/mm/yy");


来源:https://stackoverflow.com/questions/10533490/datetimepicker-getdate-to-return-date-time-in-utc-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!