我有以下代码:
var actualDate=new Date();
actualDate.format("YYYY-mm-dd HH-MM-ss.l");
我的浏览器抱怨第二行:
Uncaught TypeError: undefined is not a function
如何解决此问题?
答案 0 :(得分:2)
JavaScript Date
objects没有内置format
功能。如果您需要,您必须直接或通过库将其添加到Date.prototype
。< / p>
这不仅仅是一个名称的东西:JavaScript的Date
对象根本就没有格式化功能。它们具有可用于构建的各种功能,它们会为您提供toString
,toUTCString
,toLocaleString
和toISOString
,但这些功能不会不允许你控制格式。