JavaScript | Dateから月をフルスペルの英単語で取得する

JavaScriptのDateオブジェクトから月をフルスペルの英単語で取得する方法のサンプルコードです。
See the Pen JavaScript | Get the moon in full spelled english by yochans (@yochans) on CodePen.
Dateから月をフルスペルの英単語で取得
月の配列を用意してgetMonth()で得られる0~11の値をキー名にして取得するサンプルコードです。
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
let day = new Date();
let month_name = months[day.getMonth()];
console.log(month_name);
//January
Intl.DateTimeFormat()のオプション(month: 'long’)を指定して利用して英語の月スペルを取得するサンプルコードです。
let day = new Date();
let month_name = new Intl.DateTimeFormat('en', { month: 'long'}).format(day);
console.log(month_name);
//January
ディスカッション
コメント一覧
まだ、コメントがありません