jQuery datetimepicker getDate 以 UTC 格式返回日期/时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10533490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
datetimepicker getDate to return Date / Time in UTC format
提问by Programmer
I happen to read this datetimepickeraddon 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:
我碰巧阅读了这个datetimepicker插件,发现它很有用。我使用这个工具面临的问题是我无法以 UTC 或其他格式获取数据/时间格式(我的意图是至少以 UTC 格式获取日期/时间:
$('#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?
DD-MM-YYYY 或 DD/MM/YYYY 还是 UTC 格式?
回答by Tats_innit
Demo: http://jsfiddle.net/Dgnjn/2/
演示:http: //jsfiddle.net/Dgnjn/2/
or
或者
dd-mm-yy here http://jsfiddle.net/Dgnjn/5/
dd-mm-yy 这里http://jsfiddle.net/Dgnjn/5/
Now using datetimepicker
现在使用 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());
}
});
回答by Ankur Verma
These are some of the date formats: http://jqueryui.com/demos/datepicker/#date-formats
这些是一些日期格式:http: //jqueryui.com/demos/datepicker/#date-formats
$('#starttime').datetimepicker( "option", "dateFormat", "dd/mm/yy");