[英]format - undefined is not a function for Date object
我有以下代碼:
var actualDate=new Date();
actualDate.format("YYYY-mm-dd HH-MM-ss.l");
我的瀏覽器抱怨第二行:
Uncaught TypeError: undefined is not a function
如何解決這個問題?
JavaScript Date
對象沒有內置的format
功能。如果需要format
功能,則必須直接或通過庫將其添加到Date.prototype
。
這也不只是一個名稱問題:JavaScript的Date
對象根本沒有任何格式化功能。 它們具有可用於構建一個的各種函數,並且它們為您提供toString
, toUTCString
, toLocaleString
和toISOString
,但是這些不能讓您控制格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.