简体   繁体   English

哪个JAvaScript库定义了JavaScript Date Object的格式函数?

[英]Which JAvaScript libary defines JavaScript Date Object's format function?

Here are some of the javascript libraries & css files being used on my project that pertain to date, time, calendar,etc.: 这是我的项目中使用的一些与日期,时间,日历等有关的javascript库和css文件:

<link rel="stylesheet" href="plugins/bootstrap-datepicker/css/datepicker3.css" />
<link href="plugins/datepicker/jquery.datetimepicker.css" rel="stylesheet" type="text/css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js"  type="text/javascript"></script>
<script src="../plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<script src="../plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
  <script src="../plugins/datepicker/jquery.datetimepicker.js" type="text/javascript"></script>

In one of my ASPX pages, I have the following JavaScript code: 在我的ASPX页面之一中,我具有以下JavaScript代码:

                var d = new Date();
                var startdate = d.format("MM/dd/yyyy");
                var enddate = d.format("MM/dd/yyyy");

I've been trying to resolve the following error by searching the internet for various JavaScript libraries that pertain to date, time, calendar, etc., and then adding the said libraries to my project, and referring to them in the ASPX page: 我一直在尝试通过以下方法解决以下错误:在互联网上搜索与日期,时间,日历等有关的各种JavaScript库,然后将所述库添加到我的项目中,并在ASPX页中对其进行引用:

Uncaught TypeError: d.format is not a function

However, None of the references to the libraries seem to work. 但是,对这些库的引用似乎都无效。

Could someone please tell me which javascript library I should reference in order to remove the aforementioned error? 有人可以告诉我应该删除哪个JavaScript库,以消除上述错误吗?

As you are already referencing moment use its format() function 由于您已经在参考时刻,请使用其format()函数

 var startdate = moment(d).format("MM/DD/YYYY")

 var d = new Date(); snippet.log(moment(d).format("MM/DD/YYYY")); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js" type="text/javascript"></script> <!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 --> <script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script> 

尝试http://momentjs.com/。这是我发现直到日期都可以使用日期的最佳库。

parseDate(String(d.year));

or 要么

parseDate(d.year.toString());

However, keep in mind that the same result – a Date object – could be achieved natively, like this: 但是,请记住,可以本地实现相同的结果– Date对象,如下所示:

var date = new Date(d.year, 0);// The required 0, is for January

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

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