繁体   English   中英

[angular-ui datepicker指令]中的date()返回昨天的日期

[英]date() in [angular-ui datepicker directive] returns yesterday's date

我有使用angular-ui datepicker指令的日期选择 ,但是当我选择一个日期时,它会显示前一天。 并通过控制台进行了尝试,结果仍然存在。

我不了解这个问题的主要原因。

日期

Date构造函数在将字符串传递给它时仅能识别几种格式。 您需要使用Date.parse,它可以识别更多格式并生成传入的日期字符串的表示形式,以自Epoch以来的毫秒数表示,而Epoch则将被构造方法接受并生成所需的date对象。

var date = new Date(Date.parse("2015-07-27T22:00:00.000Z"));

文档指定您需要将日期传递为

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 &amp; 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM