虽然我会建议您验证日期服务器并进行修改如果可能的话,例如用户可能没有javascript,并且手动将日期放在那里,无论如何您都应该尝试将日期转换为日期(使用strtotime的php),并且您可以使用相同的块将js时间戳转换为unix时间戳!您需要做的很多事情才能在客户端做出这样的防弹,因为我会解释一种情况,但回答您的问题并按照您的方式进行操作,这是一种开始的方式:
您需要创建一个单独的输入字段显示jQuery UI的日期选择器可以称之为
<input id='display_startdate' type='text' name='does-not-matter-server-will-not-use-this'>
,然后你的旧<input type='hidden' name='startdate' id='startdate'>
将被用于服务器端的代码,但你不会在这一领域应用的jQuery日期选择器。你可以把它作为类型文本进行测试,然后将其更改为隐藏,因为用户不需要看到这个!
$(function(){
$("#display_startdate").datepicker({
altFormat: '@' ,
altField: '#Inspection_End',
//now the lines below will divide the ms by 1000 to give you POSIX TIMESTAMP
onSelect: function() {
fixTime();
}
});
});
//There are other times you need to evaluate the value of this field
//as an example some browsers will keep the input user entered on page refresh
//but will not keep the value javascript created
$('#yourForm').submit(function(){
//or $('#yourSubmit').click(function(){
fixTime();
//do rest!
});
function fixTime(){
$('#startdate').val($('#startdate').val()/1000);
}
来源
2011-05-25 18:04:59
Neo
我试图从jquery.ui.datepicker.js中除以1000,但我不知道该在哪里做。我试过的两个地方都导致时间戳显示负数。 – dallen 2010-08-04 18:48:02
嗯......你有最新版本的插件吗?看来这个问题已经在4.0.0版本中得到了纠正 – aletzo 2010-08-04 21:15:02