Ero*_*ing 5 php jquery datetime datepicker
我正在尝试做一些似乎应该简单的事情,但不知何故不能正确绑定.
用户从我启用的jquery datepicker中选择一个日期showWeek.
$(".datepicker").datepicker({
showWeek: true,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
Run Code Online (Sandbox Code Playgroud)
但是,当结果日期字符串被输入到php日期时间时,该周不对应,并且将在未来一周内进行.
$start_date = isset($_POST['startdate']) ? $_POST['startdate'] : "";
$start = new DateTime($start_date);
echo $start->format("W");
Run Code Online (Sandbox Code Playgroud)
IE浏览器,2018-10-02显示为我的日期选择器中的第39周,但上面的回显从读取日期回到日期时间和格式为星期返回第40周.
所以,据我所知,jquery datepicker和php datetime类不同意默认情况下哪几周.
有没有办法调和这个?
好的,这是解决方案:根据 jquery ui,您需要指定第一天,而在您的代码中您缺少它:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Show week of the year</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker({
showWeek: true,
firstDay: 1,
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
} );
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>Run Code Online (Sandbox Code Playgroud)
只需添加firstDay:1,一切都会按您的预期进行。
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |