我有基于 javascript jquery-ui datepicker 库的函数,用于选择 from_date - to_date 范围并发布到 php。发布到 php 的格式为:
2015 年 5 月 13 日星期三 00:00:00 GMT+0200(中欧夏令时间)
如何在我的函数中设置日期选择器发布到 php 的格式,例如 2015-05-20?
function updateResults() {
$.getJSON('results.php', {
from_date: fromDate.datepicker('getDate').toString(),
to_date: toDate.datepicker('getDate').toString()
}, function(data,status, xhr) {
$.plot('#flotcontainer', data, options);
});
}
//create a couple of date textboxes
$.datepicker.setDefaults
({
dateFormat: 'dd/mm/yy', defaultDate: '-1w', changeMonth: true, changeYear: true,
maxDate: 0, showButtonPanel: true, showWeek: true
});
var fromDate = $('#from').datepicker
({
onSelect: function()
{
var option = this.id == 'from' ? 'minDate': 'maxDate';
toDate.not(this).datepicker('option', option, $(this).datepicker('getDate'));
updateResults(); // When a new date is selected update the results
}
});
var toDate = $('#to').datepicker
({
onSelect: function()
{
updateResults(); // When a new date is selected update the results
}
});
//Set the default from and to dates.
fromDate.datepicker('setDate', '-1w');
toDate.datepicker('setDate', '+0');
updateResults(); // Initial call on load
});
最佳答案
Format is posted to php as:
Wed May 13 2015 00:00:00 GMT+0200 (Central European Summer Time)
首先从中创建一个时间戳:
$ts = strtotime($_POST['date']);
How can I set format 2015-05-20 for datepicker post to php in my function?
有了时间戳,您可以使用日期:
$date = date("Y-m-d", $ts);
关于javascript - 如何将 yy-mm-dd 日期选择器帖子格式化为 php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30352072/