Intl.DateTimeFormatによる日本の元号カレンダー日付

Intl.DateTimeFormatで日本の元号カレンダー(令和、平成、昭和)を使用して日付をフォーマットします。-u-ca-japanese Unicode拡張と元号表示オプションについて学びます。

Intl.DateTimeFormat

詳細な説明

日本の元号カレンダーフォーマット

日本は天皇の時代に基づく独自のカレンダーシステムを使用しています。現在の元号は令和で、2019年5月1日に始まりました。Intl.DateTimeFormat APIは-u-ca-japanese Unicode拡張を通じてこのカレンダーをサポートしています。

基本的な日本の元号フォーマット

const date = new Date('2025-03-15');

new Intl.DateTimeFormat('ja-JP-u-ca-japanese', {
  dateStyle: 'full',
}).format(date);
// "令和7年3月15日土曜日"

new Intl.DateTimeFormat('ja-JP-u-ca-japanese', {
  dateStyle: 'long',
}).format(date);
// "令和7年3月15日"

元号表示オプション

new Intl.DateTimeFormat('ja-JP-u-ca-japanese', {
  era: 'long',
  year: 'numeric',
  month: 'long',
  day: 'numeric',
}).format(date);
// "令和7年3月15日"

new Intl.DateTimeFormat('ja-JP-u-ca-japanese', {
  era: 'narrow',
  year: 'numeric',
}).format(date);
// "R7年"

日本の元号年表

元号 開始日 終了日
令和 2019-05-01 現在
平成 1989-01-08 2019-04-30
昭和 1926-12-25 1989-01-07
大正 1912-07-30 1926-12-24
明治 1868-10-23 1912-07-29

元号をまたぐフォーマット

// 平成の日付
const heisei = new Date('2018-06-15');
new Intl.DateTimeFormat('ja-JP-u-ca-japanese', {
  dateStyle: 'long',
}).format(heisei);
// "平成30年6月15日"

英語での日本暦の使用

new Intl.DateTimeFormat('en-US-u-ca-japanese', {
  era: 'long',
  year: 'numeric',
  month: 'long',
  day: 'numeric',
}).format(new Date('2025-03-15'));
// "March 15, 7 Reiwa"

ユースケース

日本の元号カレンダーサポートは、特に政府、法律、金融の文脈で日本のユーザーにサービスを提供するアプリケーションにとって不可欠です。日本の公式文書、書式、通信では元号ベースの日付が標準です。生年月日を受け付ける日本のフォームは元号入力をサポートする必要があります。日本の財務報告や法的提出書類には元号形式の日付が必要です。

試してみる — Locale String Tester

フルツールを開く