日期时间选择器的格式日期

问题描述:

如何格式化日期?我可以很容易地格式化时间,但不是日期。日期时间选择器的格式日期

http://trentrichardson.com/examples/timepicker/

它使用jQuery UI的正常日期时间。

$('.date').datetimepicker({ 
    timeFormat: 'hh:mm', 
}); 

这也不起作用:

$('.date').datetimepicker({ 
    timeFormat: 'hh:mm', 
    dateFormat: 'yy-mm-dd' //This does nothing and does not format the data 
}); 

我如何格式化从这个新的插件的日期?

尝试设置日期选取器的默认格式。

$.datepicker.setDefaults({dateFormat: 'yy-mm-dd' }); 

这应该工作,因为timepicker似乎是包装datepicker。

你不应该在同一时间设置这些吗?

$('.date').timepicker({  
    timeFormat: 'hh:mm', 
    dateFormat: 'yy-mm-dd' 
}); 
+0

这是行不通的。您不能在datetimepicker中设置dateFormat。 – 2011-05-18 23:46:33

尝试使用这样的:

$('.date').timepicker({ 
    timeFormat: 'hh:mm', 
}); 

$('.date').datepicker({ 
    dateFormat: 'yy-mm-dd' //The day format is tied to the datepicker script rather than to the timepicker script 
}); 

你应该使用

$('.date').datetimepicker({  
     timeFormat: 'hh:mm', 
     dateFormat: 'yy-mm-dd' 
    });