简体   繁体   English

将“日期时间”设置为“ jQuery日期时间选择器”

[英]Set Date Time to Jquery date time picker

I have date in Javascript 我有用Javascript约会

Sun Feb 15 2015 08:02:00 GMT+0200 (EET)

how I can to set in format ' dd/mm/yyyy hh:mm:ss ' into datetime picker? 如何将“ dd/mm/yyyy hh:mm:ss ”格式设置为日期时间选择器?

If I set like this: 如果我这样设置:

dateStart dateStart

Sun Feb 15 2015 08:02:00 GMT+0200 (EET) 2015年2月15日,星期日08:02:00 GMT + 0200(EET)

$('#dateTimeStart').datetimepicker('setDate', dateStart); $('#dateTimeStart')。datetimepicker('setDate',dateStart);

Error parsing the date/time string: Missing number at position 10 date/time string = 02-15-2015 08:02:00 timeFormat = HH:mm dateFormat = mm-dd-yyyy 解析日期/时间字符串时出错:位置10的日期/时间字符串缺少数字= 02-15-2015 08:02:00 timeFormat = HH:mm dateFormat = mm-dd-yyyy

$('#dateTimeStart').datetimepicker({
        dateFormat: 'yy-dd-mm'
        timeFormat: "hh:mm:ss"
    });

You have to format date that you have. 您必须格式化日期。 You can do it with help of function that you can grab here . 您可以在这里获取的功能的帮助下进行操作。

Usage: 用法:

<script>
  document.write($.format.date("Sun Feb 15 2015 08:02:00", "dd/mm/yyyy hh:mm:ss"));
</script>

It's small and really nice solution that can help you to resolve your issue. 这是一个很小且非常不错的解决方案,可以帮助您解决问题。

You're looking for a format like 您正在寻找类似的格式

jQuery('#dateTimeStart').datetimepicker({
    format:'d/m/Y H:i:s'
});

According to the DateTimePicker documentation at http://xdsoft.net/jqplugins/datetimepicker/ , the 'format' string is based on the PHP date format strings, which you can read up on at http://php.net/manual/en/function.date.php . 根据http://xdsoft.net/jqplugins/datetimepicker/上的DateTimePicker文档,“格式”字符串基于PHP日期格式字符串,您可以在http://php.net/manual/上进行阅读。 zh / function.date.php Note in particular they use just one letter to represent multiple numbers (eg 'd' instead of 'dd') 请特别注意,它们仅使用一个字母表示多个数字(例如,用“ d”代替“ dd”)

use below javascript code to change formate 使用下面的JavaScript代码更改formate

 var date = new Date('Sun Feb 15 2015 08:02:00 GMT+0200');

 var day    = date.getDate();
 var month  = date.getMonth();
 var year  = date.getFullYear();
 var hours = date.getHours();
 var minutes = "0" + date.getMinutes();
 var seconds = "0" + date.getSeconds();

 var fulldate = day+'/'+(month+1)+'/'+year+' '+hours + ':' + minutes.substr(minutes.length-2) + ':' + seconds.substr(seconds.length-2);

see working copy of fiddle 看到小提琴的工作副本

you can create function which return date in format 您可以创建以格式返回日期的函数

function convertdate(param){
    var date = new Date(param);
    var day    = date.getDate();
    var month  = date.getMonth();
    var year  = date.getFullYear();
    var hours = date.getHours();
    var minutes = "0" + date.getMinutes();
    var seconds = "0" + date.getSeconds();

    return fulldate = day+'/'+(month+1)+'/'+year+' '+hours + ':' + minutes.substr(minutes.length-2) + ':' + seconds.substr(seconds.length-2);
}
alert(convertdate('Sun Feb 15 2015 08:02:00 GMT+0200'));

I change format of date from server in this : ' 02/15/2015 08:02:00 AM ' and then I parse this string and create new date: 我在以下服务器中更改了日期格式: 02/15/2015 08:02:00 AM ',然后我解析了此字符串并创建了新日期:

var dateString ='02/15/2015 08:02:00 AM';
var dateStart = new Date(Date.parse(dateString, "mm/dd/yyyy hh:mm:ss"));
$('#dateTimeStart').datetimepicker('setDate', dateStart);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM