[英]toLocaleDateString is not defined how to fix?
This is one module that I have put in the views folder for ejs to render and I wish to use it to get date for my site.这是我放在 views 文件夹中供 ejs 呈现的一个模块,我希望用它来获取我的站点的日期。 This is my code:
这是我的代码:
module.exports = getDate;
function getDate(){
let today = new Date();
let options = {weekday: "long", day: "numeric", month: "long"};
let date = toLocaleDateString("en-US", options);
return date;
}
Here you made a simple mistake.在这里你犯了一个简单的错误。 (toLocaleDateString) is a property of the date object. That's why you get undefined.
(toLocaleDateString) 是日期 object 的属性。这就是你未定义的原因。 The below code is now workable.
下面的代码现在是可行的。
function getDate(){ let today = new Date(); let options = {weekday: "long", day: "numeric", month: "long"}; let date = today.toLocaleDateString("en-US", options); return date; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.