小编典典

从日期获取月份名称

all

如何从 JavaScript 中的这个日期对象生成月份的名称(例如:Oct/October)?

var objDate = new Date("10/11/2009");

阅读 94

收藏
2022-03-01

共1个答案

小编典典

较短的版本:

const monthNames = ["January", "February", "March", "April", "May", "June",

  "July", "August", "September", "October", "November", "December"

];



const d = new Date();

document.write("The current month is " + monthNames[d.getMonth()]);
2022-03-01