这是我的表格
<div id="dateSelectors" >
<form action="#" method="post" style="display:inline">
<label for="fromDate">From : </label>
<input type="text" name="fromDate" class="datepicker"/>
<label from="toDate">To : </label>
<input type="text" name="toDate" class="datepicker"/>
<input type="submit" value="Go" class="add_btn" id="go_btn" name="go_btn"/>
<input type="submit" value="View All" class="add_btn" id="viewAll" name="viewAll"/>
</form>
</div>
这是我在同一页面的PHP代码:
if(isset($_POST['go_btn'])){
$stmt;
if(isset($_POST['toDate']))
$to=date('d/m/Y',strtotime($_POST['toDate']));
if(isset($_POST['fromDate']))
$from=date('d/m/Y',strtotime($_POST['fromDate']));
}
当我填写这样的字段时 来自:2014年7月1日至:2014年7月21日。
我得到: echo $ _POST ['fromDate']为01/07/2014。 但是$ _POST ['toDate']为1970年1月1日。 请帮帮我。
答案 0 :(得分:1)
您使用的是jquery datepicker吗?
如果是,您需要对每个元素进行实例化:
$('.datepicker').each(function(){
$(this).datepicker();
});
答案 1 :(得分:1)
$to=date('d/m/Y',strtotime($_POST['toDate']));
我看起来strtotime
在解析时找不到有效日期。确保php正在使用您的语言环境!我猜这是因为当您输出日期时,您使用的是日期格式。
您可以使用php函数setlocale
设置本地。