[英]format - undefined is not a function for Date object
I have following code: 我有以下代码:
var actualDate=new Date();
actualDate.format("YYYY-mm-dd HH-MM-ss.l");
My browser complains about second row: 我的浏览器抱怨第二行:
Uncaught TypeError: undefined is not a function
How to fix this issue? 如何解决这个问题?
JavaScript Date
objects don't have a format
function built in. If you want one, you'll have to add it to Date.prototype
, either directly or via a library. JavaScript
Date
对象没有内置的format
功能。如果需要format
功能,则必须直接或通过库将其添加到Date.prototype
。
It's not just a name thing, either: JavaScript's Date
objects just don't have a formatting function at all. 这也不只是一个名称问题:JavaScript的
Date
对象根本没有任何格式化功能。 They have various functions you can use to build one, and they give you toString
, toUTCString
, toLocaleString
, and toISOString
, but those don't let you control the format. 它们具有可用于构建一个的各种函数,并且它们为您提供
toString
, toUTCString
, toLocaleString
和toISOString
,但是这些不能让您控制格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.