简体   繁体   中英

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. 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. 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; }

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