Reputation: 8727
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?
Upvotes: 5
Views: 52081
Reputation: 34117
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());
}
});
Upvotes: 4
Reputation: 5933
These are some of the date formats: http://jqueryui.com/demos/datepicker/#date-formats
$('#starttime').datetimepicker( "option", "dateFormat", "dd/mm/yy");
Upvotes: 0