★ wanayoo — archive 1999 https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormatNouvelle recherche | Portail wanayoo
mozilla
Your Search Results

    Intl.DateTimeFormat

    This article is in need of an editorial review.

    This translation is in progress.

    概要

    言語に敏感な日付と時刻のフォーマットを有効にするオブジェクトのコンストラクタです。

    構文

    new Intl.DateTimeFormat([locales[, options]])
    Intl.DateTimeFormat.call(this[, locales[, options]])

    引数

    locales

    オプション。BCP47言語タグをもつ文字列、または、そのような文字列の配列。 locales引数の一般的な形式と解釈のために、Intl pageを確かめて下さい。. 次のUnicode拡張キーが許可されています。:

    nu
    番号方式。可能な値は以下のとおりです。: "arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt"
    ca
    カレンダー。可能な値は以下のとおりです。: "buddhist", "chinese", "coptic", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamicc", "iso8601", "japanese", "persian", "roc"
    options

    オプション。次のプロパティの一部またはすべてを持つオブジェクト:

    localeMatcher
    使用するローケルマッチングアルゴリズム。可能な値は"lookup"と"best fit"です。デフォルトは"best fit"です。このオプションについての詳細は、Intl pageを確かめて下さい。
    timeZone
    使用するタイムゾーン。実装が認識しなければならない唯一の値は"UTC"です。デフォルトは、実行時のデフォルトのタイムゾーンです。実装は、また、"Asia/Shanghai", "Asia/Kolkata", "America/New_York"のようなIANA time zone databaseのタイムゾーン名を認識することができます。
    hour12
    12時間の時間を使用するかどうか (24時間の時間とは対照的に)。可能な値はtrue と falseです。デフォルトは、ローケル依存です。
    formatMatcher
    使用するフォーマットマッチングアルゴリズム。可能な値は"basic" と "best fit"です。デフォルトは、"best fit"です。このプロパティの使用方法については、以下の項を参照してください。

    次のプロパティは、日付·時刻のコンポーネントやそれらの所望の表現をフォーマットされた出力で使用するように記述します。実装は、少なくとも以下のサブセットをサポートするために必要です。:

    • weekday, year, month, day, hour, minute, second
    • weekday, year, month, day
    • year, month, day
    • year, month
    • month, day
    • hour, minute, second
    • hour, minute

    実装は、他のサブセットをサポートすることができ、要求は、ベストマッチを見つけるために、すべての利用可能なサブセットの表現の組み合わせに対してネゴシエートされます。二つのアルゴリズムがこのネゴシエートに対して利用可能で、formatMatcherプロパティによって選択されます。:fully specified "basic" algorithm と実装は an implementationは、"best fit" アルゴリズムに依存しています。

    weekday
    平日の表現。可能な値は、"narrow", "short", "long"です。
    era
    時代の表現。可能な値は"narrow", "short", "long"です。
    year
    今年の表現。可能な値は"numeric", "2-digit"です。
    month
    月の表現。可能な値は"numeric", "2-digit", "narrow", "short", "long"です。
    day
    日の表現。可能な値は"numeric", "2-digit"です。
    hour
    時間の表現。可能な値は"numeric", "2-digit"です。
    minute
    分の表現。可能な値は"numeric", "2-digit"です。
    second
    秒の表現。可能な値は"numeric", "2-digit"です。
    timeZoneName
    タイムゾーン名の表現。可能な値は"short", "long"です。

    各日付時間コンポーネントプロパティのデフォルト値はundefinedです。しかし、すべてのコンポーネントプロパティがundefinedの場合、year、month、dayは"numeric"であると仮定されています。

    説明

    プロパティ

    Intl.DateTimeFormat.prototype
    すべてのオブジェクトにプロパティを追加できます。

    メソッド

    Intl.DateTimeFormat.supportedLocalesOf()
    実行時のデフォルトロケールにフォールバックすることなく、サポートされて提供されるロケールのものを含む配列を返します。

    DateTimeFormat インスタンス

    プロパティ

    DateTimeFormat インスタンスはプロトタイプから次のプロパティを継承します。:

    Intl.DateTimeFormat.prototype.constructor
    A reference to Intl.DateTimeFormat.
    Intl.DateTimeFormat.prototype.format
    Getter; returns a function that formats a date according to the locale and formatting options of this DateTimeFormat object.

    メソッド

    DateTimeFormat インスタンスはプロトタイプから次のメソッドを継承します。:

    Intl.DateTimeFormat.prototype.resolvedOptions()
    Returns a new object with properties reflecting the locale and formatting options computed during initialization of the object.

    例

    例: DateTimeFormatを使う

    ローケルを指定しない基本的な使用では、DateTimeFormatはデフォルトローケルとデフォルトオプションを使用します。

    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
    
    // toLocaleString without arguments depends on the implementation,
    // the default locale, and the default time zone
    console.log(new Intl.DateTimeFormat().format(date));
    // → "12/19/2012" if run in en-US locale with time zone America/Los_Angeles
    

    例: localesを使う

    この例では、ローカライズされた日付と時刻の形式の変化のいくつかを示しています。アプリケーションのユーザインターフェイスで使用される言語の形式を得るために、locales引数を使用して、その言語(おそらくいくつかのフォールバック言語)を指定してください。:

    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
    
    // formats below assume the local time zone of the locale;
    // America/Los_Angeles for the US
    
    // US English uses month-day-year order
    console.log(new Intl.DateTimeFormat('en-US').format(date));
    // → "12/19/2012"
    
    // British English uses day-month-year order
    console.log(new Intl.DateTimeFormat('en-GB').format(date));
    // → "20/12/2012"
    
    // Korean uses year-month-day order
    console.log(new Intl.DateTimeFormat('ko-KR').format(date));
    // → "2012. 12. 20."
    
    // Arabic in most Arabic speaking countries uses real Arabic digits
    console.log(new Intl.DateTimeFormat('ar-EG').format(date));
    // → "٢٠‏/١٢‏/٢٠١٢"
    
    // for Japanese, applications may want to use the Japanese calendar,
    // where 2012 was the year 24 of the Heisei era
    console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(date));
    // → "24/12/20"
    
    // when requesting a language that may not be supported, such as
    // Balinese, include a fallback language, in this case Indonesian
    console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date));
    // → "20/12/2012"
    

    例: optionsを使う

    日付と時刻のフォーマットはoptions引数を使用してカスタマイズできます。:

    var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
    
    // request a weekday along with a long date
    var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
    console.log(new Intl.DateTimeFormat('de-DE', options).format(date));
    // → "Donnerstag, 20. Dezember 2012"
    
    // an application may want to use UTC and make that visible
    options.timeZone = 'UTC';
    options.timeZoneName = 'short';
    console.log(new Intl.DateTimeFormat('en-US', options).format(date));
    // → "Thursday, December 20, 2012, GMT"
    
    // sometimes you want to be more precise
    options = {
      hour: 'numeric', minute: 'numeric', second: 'numeric',
      timeZoneName: 'short'
    };
    console.log(new Intl.DateTimeFormat('en-AU', options).format(date));
    // → "2:00:00 pm AEDT"
    
    // sometimes even the US needs 24-hour time
    options = {
      year: 'numeric', month: 'numeric', day: 'numeric',
      hour: 'numeric', minute: 'numeric', second: 'numeric',
      hour12: false
    };
    console.log(date.toLocaleString('en-US', options));
    // → "12/19/2012, 19:00:00"
    

    仕様

    仕様 ステータス コメント
    ECMAScript Internationalization API 1.0 (ECMA-402)
    The definition of 'Intl.DateTimeFormat' in that specification.
    Standard 初期定義。

    ブラウザ実装状況

    機能 Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
    基本サポート 24 29 (29) 11 15 未サポート
    機能 Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
    基本サポート 未サポート 26 未サポート
    バグ 864843
    未サポート 未サポート 未サポート

    関連情報

    ドキュメントのタグと貢献者

    Contributors to this page: Mingun, shide55
    最終更新者: shide55,