【发布时间】:2015-08-28 13:17:46
【问题描述】:
【问题讨论】:
-
您选择正确的日期,但角度转换日期为基于时区,选择日期为时间 22:00:00.000Z 并且您得到 GMT+0200 即 22+2 即第二天。
标签: javascript angularjs datepicker angular-ui
【问题讨论】:
标签: javascript angularjs datepicker angular-ui
当一个字符串被传递给它时,Date 构造函数只能识别几种格式。您需要使用 Date.parse ,它可以识别更多格式并将传入的日期字符串表示为自 Epoch 以来的毫秒数,反过来,构造函数将接受并生成所需的日期对象。
var date = new Date(Date.parse("2015-07-27T22:00:00.000Z"));
【讨论】:
documentation 指定您需要将日期传递为
new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
所以你应该把它传递为:
new Date(2015,07,27,22,00,00,0000000000);
否则您需要使用Date.parse 来正确解析日期。
附带说明:moment.js 可以很好地处理所有这些问题。
【讨论】:
可能对你有用
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Display month & year menus</title>
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true
});
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
【讨论】: