あなたのロケールで月リストを得る方法
4076 ワード
こんにちは!私は、多分あなたの時間を節約する簡単なtypescript機能を示すことがうれしいです.多くの場合、数ヶ月のセレクタを実装する必要があります.場合によっては、それは異なるロケールにあるべきです.以下を参照ください.
例えば、🇬🇧
名前の短いバージョンのために、ちょうど
例えば、🇬🇧
更新
あなたの要求によって私はpackageで機能を抽出しました
function getMonthList(
locales?: string | string[],
format: "long" | "short" = "long"
): string[] {
const year = new Date().getFullYear(); // 2020
const monthList = [...Array(12).keys()]; // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
const formatter = new Intl.DateTimeFormat(locales, {
month: format
});
const getMonthName = (monthIndex: number) =>
formatter.format(new Date(year, monthIndex));
return monthList.map(getMonthName);
}
それです.ちょっとあなたのロケールをparamとして提供してください.例えば、🇬🇧
getMonthList('en')
は戻ります.January
February
March
April
May
June
July
August
September
October
November
December
codesandboxで自分で試してみてください.名前の短いバージョンのために、ちょうど
short
として第2のPAAMを提供します.例えば、🇬🇧
getMonthList('en', 'short')
は戻ります.Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
フォローミー更新
あなたの要求によって私はpackageで機能を抽出しました
Reference
この問題について(あなたのロケールで月リストを得る方法), 我々は、より多くの情報をここで見つけました https://dev.to/pretaporter/how-to-get-month-list-in-your-language-4lfbテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol