简体   繁体   中英

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.

It's not just a name thing, either: JavaScript's Date objects just don't have a formatting function at all. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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