DateTimeFormatInfo クラスとは? わかりやすく解説

DateTimeFormatInfo クラス

カルチャに従ってDateTime 値を形式指定および表示する方法定義します

名前空間: System.Globalization
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 DateTimeFormatInfo
    Implements ICloneable, IFormatProvider
Dim instance As DateTimeFormatInfo
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class DateTimeFormatInfo : ICloneable,
 IFormatProvider
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class DateTimeFormatInfo sealed
 : ICloneable, IFormatProvider
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class DateTimeFormatInfo implements
 ICloneable, IFormatProvider
SerializableAttribute 
ComVisibleAttribute(true) 
public final class DateTimeFormatInfo implements
 ICloneable, IFormatProvider
解説解説

このクラスは、日付パターン時刻パターンAM/PM 指定子などの情報格納します

特定のカルチャの DateTimeFormatInfo作成するには、そのカルチャの CultureInfo を作成し、CultureInfo.DateTimeFormat プロパティ取得します現在のスレッドのカルチャに対して DateTimeFormatInfo作成するには、CurrentInfo プロパティ使用します。インバリアント カルチャの DateTimeFormatInfo作成するには、読み取り専用バージョンでは InvariantInfo プロパティ使用し書き込み可能バージョンでは DateTimeFormatInfo コンストラクタ使用しますニュートラル カルチャの DateTimeFormatInfo作成できません。

ユーザーは、[コントロール パネル] の [地域と言語オプション] (オペレーティング システムによっては [地域オプション] または [地域]) を使用してWindows現在のカルチャに関連付けられた値の一部オーバーライドすることもできます。たとえば、ユーザー別の形式日付表示したり、カルチャの既定通貨以外の通貨使用したりすることを選択する場合あります。CultureInfo.UseUserOverride プロパティtrue設定されている場合は、CultureInfo.DateTimeFormat、CultureInfo.NumberFormat、CultureInfo.TextInfo の各インスタンスプロパティユーザー設定から取得されます。ユーザー設定CultureInfo関連付けられたカルチャとの間に互換性ない場合 (たとえば、選択されカレンダーが OptionalCalendars のいずれかない場合)、メソッド結果およびプロパティの値は未定義です。

DateTime 値は、DateTimeFormatInfoプロパティ格納されている標準パターンまたはカスタム パターン使用して形式指定します

標準パターンは、書き込み可能 DateTimeFormatInfo関連付けられたプロパティ設定してカスタム パターン置き換えることができますDateTimeFormatInfo書き込み可能かどうか判断するには、IsReadOnly プロパティ使用します

標準パターン標準形式指定文字と、設定して標準パターン変更できる関連付けられた DateTimeFormatInfo プロパティ次の表に示します形式指定文字では大文字と小文字区別されます。たとえば、"g" と "G" は少し異なパターン表します

形式指定文字

関連付けられたプロパティ/説明

d

ShortDatePattern

D

LongDatePattern

f

完全な日付と時刻 (長い日付と短い時刻)。

F

FullDateTimePattern (長い日付長い時刻)。

g

一般 (短い日付と短い時刻)。

G

一般 (短い日付長い時刻)。

m, M

MonthDayPattern

r, R

RFC1123Pattern

s

現地時間使用する SortableDateTimePattern (ISO 8601 準拠)。

t

ShortTimePattern

T

LongTimePattern

u

世界協定時刻の表示形式使用する UniversalSortableDateTimePattern。

U

世界協定時刻を使用する完全な日付と時刻 (長い日付長い時刻)。

y, Y

YearMonthPattern

カスタム パターン構築するために組み合わせることができるパターン次の表に示しますパターンでは大文字と小文字区別されます。たとえば、"MM" は認識されますが、"mm" は認識されません。カスタム パターン空白文字または単一引用符囲まれ文字含まれる場合は、出力される文字列にもこれらの文字含まれます。形式パターン一部または形式指定文字として定義されていない文字は、そのまま出力されます。

形式指定文字列

説明

d または %d

その月の日付。1 日付で、先行ゼロ付きません。形式パターン他の形式パターン組み合わされていない場合は、"%d" を指定します

dd

その月の日付。1 の日には、先行ゼロ付きます

ddd

AbbreviatedDayNames の定義に基づく、曜日省略名。

dddd

DayNames の定義に基づく、曜日の完全名

M または %M

月を表す数値。1 の月で、先行ゼロ付きません。形式パターン他の形式パターン組み合わされていない場合は、"%M" を指定します

MM

月を表す数値。1 の月には、先行ゼロ付きます

MMM

AbbreviatedMonthNames の定義に基づく、月の省略名。

MMMM

MonthNames の定義に基づく、月の完全名

y または %y

世紀指定しい年世紀指定しい年10 未満場合、その年は先行ゼロ付けず表示されます。形式パターン他の形式パターン組み合わされていない場合は、"%y" を指定します

yy

世紀指定しい年世紀指定しい年10 未満場合、その年は先行ゼロ付けて表示されます。

yyyy

世紀を含む 4 桁の年。

gg

時期または時代 (年号)。形式指定される日付に、関連付けられた時期または時代 (年号) の文字列ない場合、このパターン無視されます。

h または %h

12 時間形式の時間。1 時刻で、先行ゼロ付きません。形式パターン他の形式パターン組み合わされていない場合は、"%h"指定します

hh

12 時間形式の時間。1 時刻で、先行ゼロ付きます

H または %H

24 時間形式時間。1 時刻で、先行ゼロ付きません。形式パターン他の形式パターン組み合わされていない場合は、"%H"指定します

HH

24 時間形式時間。1 時刻で、先行ゼロ付きます

m または %m

分。1 の分で、先行ゼロ付きません。形式パターン他の形式パターン組み合わされていない場合は、"%m" を指定します

mm

分。1 の分で、先行ゼロ付きます

s または %s

秒。1 秒で先行ゼロ付きません。形式パターン他の形式パターン組み合わされていない場合は、"%s" を指定します

ss

秒。1 の秒には、先行ゼロ付きます

f または %f

精度 1 の秒の端数残り切り捨てられます。形式パターン他の形式パターン組み合わされていない場合は、"%f" を指定します

ff

精度 2 の秒の端数残り切り捨てられます。

fff

精度 3 の秒の端数残り切り捨てられます。

ffff

精度 4 桁の秒の端数残り切り捨てられます。

fffff

精度 5 桁の秒の端数残り切り捨てられます。

ffffff

精度 6 の秒の端数残り切り捨てられます。

fffffff

精度 7 の秒の端数残り切り捨てられます。

F または %F

秒の端数の最も上位表示されます。そのが 0 の場合は、何も表示されません。形式パターン他の形式パターン組み合わされていない場合は、"%F" を指定します

FF

秒の端数の上位 2 表示されます。ただし、末尾の 0 は表示されません。2 とも 0 の場合は、どちらも表示されません。

FFF

秒の端数の上位 3 表示されます。ただし、末尾の 0 は表示されません。3 とも 0 の場合は、どの表示されません。

FFFF

秒の端数の上4 桁表示されます。ただし、末尾の 0 は表示されません。4 桁とも 0 の場合は、どの表示されません。

FFFFF

秒の端数の上5 桁表示されます。ただし、末尾の 0 は表示されません。5 桁とも 0 の場合は、どの表示されません。

FFFFFF

秒の端数の上位 6 表示されます。ただし、末尾の 0 は表示されません。6 とも 0 の場合は、どの表示されません。

FFFFFFF

秒の端数の上位 7 表示されます。ただし、末尾の 0 は表示されません。7 とも 0 の場合は、どの表示されません。

t または %t

AMDesignator または PMDesignator で定義される AM/PM 指定子の最初文字がある場合、その文字形式パターン他の形式パターン組み合わされていない場合は、"%t" を指定します

tt

AMDesignator または PMDesignator定義される AM/PM 指定子がある場合、その文字

z または %z

タイム ゾーン オフセット ("+" または "-" の後ろ時間だけを表記)。1 時刻で、先行ゼロ付きません。たとえば、太平洋標準時では "-8" です。形式パターン他の形式パターン組み合わされていない場合は、"%z" を指定します

zz

タイム ゾーン オフセット ("+" または "-" の後ろ時間だけを表記)。1 時刻で、先行ゼロ付きます。たとえば、太平洋標準時では "-08" です。

zzz

完全タイム ゾーン オフセット ("+" または "-" の後ろ時間と分を表記)。1 時間と分で、先行ゼロ付きません。たとえば、太平洋標準時では "-08:00" です。

:

TimeSeparator で定義される既定時間区切り記号

/

DateSeparator で定義される既定日付区切り記号

% c

単独使用される場合c形式パターンです。つまり、形式パターン "d"、"f"、"F"、"h""m"、"s"、"t"、"y"、"z"、"H"、または "M"単独使用する場合は、それぞれ "%d"、"%f"、"%F"、"%h"、"%m"、"%s"、"%t"、"%y"、"%z"、"%H"、または "%M" を指定します

形式パターンリテラル文字またはその他の形式パターン組み合わされている場合、"%" 文字省略できます

\ c

c任意の文字です。文字そのまま表示しますバックスラッシュ文字表示するには、"\\" を使用します

上の 2 番目の表に示した形式パターンだけをカスタム パターン作成使用できます最初の表に示した標準形式指定文字は、カスタム パターン作成使用できません。カスタム パターンは、次のように最低 2 文字にします。

ニュートラル カルチャを除くインバリアント カルチャまたは特定のカルチャに対してだけ、DateTimeFormatInfo または NumberFormatInfo を作成できます。インバリアント カルチャ、特定のカルチャ、およびニュートラル カルチャの詳細については、CultureInfo クラストピック参照してください

このクラスは、DateTimeFormatInfo オブジェクト複製できるようにする ICloneable インターフェイス実装ます。アプリケーション形式指定情報提供するために、IFormatProvider も実装ます。

使用例使用例

形式指定文字使用してen-US カルチャ用の異な形式パターン出力するコードの例次に示します。この例は、形式指定文字関連付けられているプロパティの値も表示します

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class SamplesDTFI

   Public Shared Sub Main()

      ' Creates and initializes a DateTimeFormatInfo associated with
 the en-US culture.
      Dim myDTFI As DateTimeFormatInfo = New
 CultureInfo("en-US", False).DateTimeFormat
      
      ' Creates a DateTime with the Gregorian date January 3, 2002 (year=2002,
 month=1, day=3).
      ' The Gregorian calendar is the default calendar for the en-US
 culture.
      Dim myDT As New DateTime(2002,
 1, 3)
      
      ' Displays the format pattern associated with each format character.
      Console.WriteLine("FORMAT  en-US EXAMPLE")
      Console.WriteLine("CHAR    VALUE OF ASSOCIATED PROPERTY,
 IF ANY")
      Console.WriteLine()
      Console.WriteLine("  d     {0}", myDT.ToString("d"))
      Console.WriteLine("        {0} {1}", myDTFI.ShortDatePattern,
 "(ShortDatePattern)")
      Console.WriteLine()
      Console.WriteLine("  D     {0}", myDT.ToString("D"))
      Console.WriteLine("        {0} {1}", myDTFI.LongDatePattern,
 "(LongDatePattern)")
      Console.WriteLine()
      Console.WriteLine("  f     {0}", myDT.ToString("f"))
      Console.WriteLine()
      Console.WriteLine("  F     {0}", myDT.ToString("F"))
      Console.WriteLine("        {0} {1}", myDTFI.FullDateTimePattern,
 "(FullDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  g     {0}", myDT.ToString("g"))
      Console.WriteLine()
      Console.WriteLine("  G     {0}", myDT.ToString("G"))
      Console.WriteLine()
      Console.WriteLine("  m     {0}", myDT.ToString("m"))
      Console.WriteLine("        {0} {1}", myDTFI.MonthDayPattern,
 "(MonthDayPattern)")
      Console.WriteLine()
      Console.WriteLine("  M     {0}", myDT.ToString("M"))
      Console.WriteLine("        {0} {1}", myDTFI.MonthDayPattern,
 "(MonthDayPattern)")
      Console.WriteLine()
      Console.WriteLine("  r     {0}", myDT.ToString("r"))
      Console.WriteLine("        {0} {1}", myDTFI.RFC1123Pattern,
 "(RFC1123Pattern)")
      Console.WriteLine()
      Console.WriteLine("  R     {0}", myDT.ToString("R"))
      Console.WriteLine("        {0} {1}", myDTFI.RFC1123Pattern,
 "(RFC1123Pattern)")
      Console.WriteLine()
      Console.WriteLine("  s     {0}", myDT.ToString("s"))
      Console.WriteLine("        {0} {1}", myDTFI.SortableDateTimePattern,
 "(SortableDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  t     {0}", myDT.ToString("t"))
      Console.WriteLine("        {0} {1}", myDTFI.ShortTimePattern,
 "(ShortTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  T     {0}", myDT.ToString("T"))
      Console.WriteLine("        {0} {1}", myDTFI.LongTimePattern,
 "(LongTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  u     {0}", myDT.ToString("u"))
      Console.WriteLine("        {0} {1}", myDTFI.UniversalSortableDateTimePattern,
 "(UniversalSortableDateTimePattern)")
      Console.WriteLine()
      Console.WriteLine("  U     {0}", myDT.ToString("U"))
      Console.WriteLine()
      Console.WriteLine("  y     {0}", myDT.ToString("y"))
      Console.WriteLine("        {0} {1}", myDTFI.YearMonthPattern,
 "(YearMonthPattern)")
      Console.WriteLine()
      Console.WriteLine("  Y     {0}", myDT.ToString("Y"))
      Console.WriteLine("        {0} {1}", myDTFI.YearMonthPattern,
 "(YearMonthPattern)")

   End Sub 'Main 

End Class 'SamplesDTFI


'This code produces the following output.
'
'FORMAT  en-US EXAMPLE
'CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY
'
'  d     1/3/2002
'        M/d/yyyy (ShortDatePattern)
'
'  D     Thursday, January 03, 2002
'        dddd, MMMM dd, yyyy (LongDatePattern)
'
'  f     Thursday, January 03, 2002 12:00 AM
'
'  F     Thursday, January 03, 2002 12:00:00 AM
'        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)
'
'  g     1/3/2002 12:00 AM
'
'  G     1/3/2002 12:00:00 AM
'
'  m     January 03
'        MMMM dd (MonthDayPattern)
'
'  M     January 03
'        MMMM dd (MonthDayPattern)
'
'  r     Thu, 03 Jan 2002 00:00:00 GMT
'        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
'  R     Thu, 03 Jan 2002 00:00:00 GMT
'        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)
'
'  s     2002-01-03T00:00:00
'        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)
'
'  t     12:00 AM
'        h:mm tt (ShortTimePattern)
'
'  T     12:00:00 AM
'        h:mm:ss tt (LongTimePattern)
'
'  u     2002-01-03 00:00:00Z
'        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)
'
'  U     Thursday, January 03, 2002 8:00:00 AM
'
'  y     January, 2002
'        MMMM, yyyy (YearMonthPattern)
'
'  Y     January, 2002
'        MMMM, yyyy (YearMonthPattern)
'
using System;
using System.Globalization;


public class SamplesDTFI  {

   public static void Main()
  {

      // Creates and initializes a DateTimeFormatInfo associated with
 the en-US culture.
      DateTimeFormatInfo myDTFI = new CultureInfo( "en-US",
 false ).DateTimeFormat;

      // Creates a DateTime with the Gregorian date January 3, 2002
 (year=2002, month=1, day=3).
      // The Gregorian calendar is the default calendar for the en-US
 culture.
      DateTime myDT = new DateTime( 2002, 1, 3 );

      // Displays the format pattern associated with each format character.
      Console.WriteLine( "FORMAT  en-US EXAMPLE" );
      Console.WriteLine( "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n"
 );
      Console.WriteLine( "  d     {0}", myDT.ToString("d") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortDatePattern,
 "(ShortDatePattern)" );
      Console.WriteLine( "  D     {0}", myDT.ToString("D") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongDatePattern, "(LongDatePattern)"
 );
      Console.WriteLine( "  f     {0}\n", myDT.ToString("f")
 );
      Console.WriteLine( "  F     {0}", myDT.ToString("F") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.FullDateTimePattern,
 "(FullDateTimePattern)" );
      Console.WriteLine( "  g     {0}\n", myDT.ToString("g")
 );
      Console.WriteLine( "  G     {0}\n", myDT.ToString("G")
 );
      Console.WriteLine( "  m     {0}", myDT.ToString("m") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)"
 );
      Console.WriteLine( "  M     {0}", myDT.ToString("M") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.MonthDayPattern, "(MonthDayPattern)"
 );
      Console.WriteLine( "  r     {0}", myDT.ToString("r") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)"
 );
      Console.WriteLine( "  R     {0}", myDT.ToString("R") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.RFC1123Pattern, "(RFC1123Pattern)"
 );
      Console.WriteLine( "  s     {0}", myDT.ToString("s") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.SortableDateTimePattern,
 "(SortableDateTimePattern)" );
      Console.WriteLine( "  t     {0}", myDT.ToString("t") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.ShortTimePattern,
 "(ShortTimePattern)" );
      Console.WriteLine( "  T     {0}", myDT.ToString("T") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.LongTimePattern, "(LongTimePattern)"
 );
      Console.WriteLine( "  u     {0}", myDT.ToString("u") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.UniversalSortableDateTimePattern,
 "(UniversalSortableDateTimePattern)" );
      Console.WriteLine( "  U     {0}\n", myDT.ToString("U")
 );
      Console.WriteLine( "  y     {0}", myDT.ToString("y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern,
 "(YearMonthPattern)" );
      Console.WriteLine( "  Y     {0}", myDT.ToString("Y") );
      Console.WriteLine( "        {0} {1}\n", myDTFI.YearMonthPattern,
 "(YearMonthPattern)" );

   }

}

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

  d     1/3/2002
        M/d/yyyy (ShortDatePattern)

  D     Thursday, January 03, 2002
        dddd, MMMM dd, yyyy (LongDatePattern)

  f     Thursday, January 03, 2002 12:00 AM

  F     Thursday, January 03, 2002 12:00:00 AM
        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

  g     1/3/2002 12:00 AM

  G     1/3/2002 12:00:00 AM

  m     January 03
        MMMM dd (MonthDayPattern)

  M     January 03
        MMMM dd (MonthDayPattern)

  r     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  R     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  s     2002-01-03T00:00:00
        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

  t     12:00 AM
        h:mm tt (ShortTimePattern)

  T     12:00:00 AM
        h:mm:ss tt (LongTimePattern)

  u     2002-01-03 00:00:00Z
        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

  U     Thursday, January 03, 2002 8:00:00 AM

  y     January, 2002
        MMMM, yyyy (YearMonthPattern)

  Y     January, 2002
        MMMM, yyyy (YearMonthPattern)

*/
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes a DateTimeFormatInfo associated with the
 en-US culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false
 );
   DateTimeFormatInfo^ myDTFI = MyCI->DateTimeFormat;
   
   // Creates a DateTime with the Gregorian date January 3, 2002 (year=2002,
 month=1, day=3).
   // The Gregorian calendar is the default calendar for the en-US culture.
   DateTime myDT = DateTime(2002,1,3);
   
   // Displays the format pattern associated with each format character.
   Console::WriteLine( "FORMAT  en-US EXAMPLE" );
   Console::WriteLine( "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n"
 );
   Console::WriteLine( "  d {0}", myDT.ToString( "d" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->ShortDatePattern, "(ShortDatePattern)"
 );
   Console::WriteLine( "  D {0}", myDT.ToString( "D" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->LongDatePattern, "(LongDatePattern)"
 );
   Console::WriteLine( "  f {0}\n", myDT.ToString( "f" ) );
   Console::WriteLine( "  F {0}", myDT.ToString( "F" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->FullDateTimePattern, "(FullDateTimePattern)"
 );
   Console::WriteLine( "  g {0}\n", myDT.ToString( "g" ) );
   Console::WriteLine( "  G {0}\n", myDT.ToString( "G" ) );
   Console::WriteLine( "  m {0}", myDT.ToString( "m" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->MonthDayPattern, "(MonthDayPattern)"
 );
   Console::WriteLine( "  M {0}", myDT.ToString( "M" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->MonthDayPattern, "(MonthDayPattern)"
 );
   Console::WriteLine( "  r {0}", myDT.ToString( "r" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->RFC1123Pattern, "(RFC1123Pattern)"
 );
   Console::WriteLine( "  R {0}", myDT.ToString( "R" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->RFC1123Pattern, "(RFC1123Pattern)"
 );
   Console::WriteLine( "  s {0}", myDT.ToString( "s" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->SortableDateTimePattern,
 "(SortableDateTimePattern)" );
   Console::WriteLine( "  t {0}", myDT.ToString( "t" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->ShortTimePattern, "(ShortTimePattern)"
 );
   Console::WriteLine( "  T {0}", myDT.ToString( "T" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->LongTimePattern, "(LongTimePattern)"
 );
   Console::WriteLine( "  u {0}", myDT.ToString( "u" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->UniversalSortableDateTimePattern,
 "(UniversalSortableDateTimePattern)" );
   Console::WriteLine( "  U {0}\n", myDT.ToString( "U" ) );
   Console::WriteLine( "  y {0}", myDT.ToString( "y" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->YearMonthPattern, "(YearMonthPattern)"
 );
   Console::WriteLine( "  Y {0}", myDT.ToString( "Y" ) );
   Console::WriteLine( " {0} {1}\n", myDTFI->YearMonthPattern, "(YearMonthPattern)"
 );
}

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

d     1/3/2002
M/d/yyyy (ShortDatePattern)

D     Thursday, January 03, 2002
dddd, MMMM dd, yyyy (LongDatePattern)

f     Thursday, January 03, 2002 12:00 AM

F     Thursday, January 03, 2002 12:00:00 AM
dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

g     1/3/2002 12:00 AM

G     1/3/2002 12:00:00 AM

m     January 03
MMMM dd (MonthDayPattern)

M     January 03
MMMM dd (MonthDayPattern)

r     Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

R     Thu, 03 Jan 2002 00:00:00 GMT
ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

s     2002-01-03T00:00:00
yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

t     12:00 AM
h:mm tt (ShortTimePattern)

T     12:00:00 AM
h:mm:ss tt (LongTimePattern)

u     2002-01-03 00:00:00Z
yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

U     Thursday, January 03, 2002 8:00:00 AM

y     January, 2002
MMMM, yyyy (YearMonthPattern)

Y     January, 2002
MMMM, yyyy (YearMonthPattern)

*/
import System.* ;
import System.Globalization.* ;

public class SamplesDTFI
{
    public static void main(String[]
 args)
    {
        // Creates and initializes a DateTimeFormatInfo associated with
 
        // the en-US culture.
        DateTimeFormatInfo myDTFI = 
            (new CultureInfo("en-US", false)).get_DateTimeFormat();

        // Creates a DateTime with the Gregorian date January 3, 2002
 
        // (year=2002, month=1, day=3).
        // The Gregorian calendar is the default calendar for the 
        // en-US culture.
        DateTime myDT =  new DateTime(2002, 1, 3);

        // Displays the format pattern associated with each format character.
        Console.WriteLine("FORMAT  en-US EXAMPLE");
        Console.WriteLine("CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY\n");
        Console.WriteLine("  d     {0}", myDT.ToString("d"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_ShortDatePattern()
,
            "(ShortDatePattern)");
        Console.WriteLine("  D     {0}", myDT.ToString("D"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_LongDatePattern(),
 
            "(LongDatePattern)");
        Console.WriteLine("  f     {0}\n", myDT.ToString("f"));
        Console.WriteLine("  F     {0}", myDT.ToString("F"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_FullDateTimePattern()
,
            "(FullDateTimePattern)");
        Console.WriteLine("  g     {0}\n", myDT.ToString("g"));
        Console.WriteLine("  G     {0}\n", myDT.ToString("G"));
        Console.WriteLine("  m     {0}", myDT.ToString("m"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_MonthDayPattern(),
 
            "(MonthDayPattern)");
        Console.WriteLine("  M     {0}", myDT.ToString("M"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_MonthDayPattern(),
 
            "(MonthDayPattern)");
        Console.WriteLine("  r     {0}", myDT.ToString("r"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_RFC1123Pattern()
,
            "(RFC1123Pattern)");
        Console.WriteLine("  R     {0}", myDT.ToString("R"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_RFC1123Pattern()
, 
            "(RFC1123Pattern)");
        Console.WriteLine("  s     {0}", myDT.ToString("s"));
        Console.WriteLine("        {0} {1}\n", 
            myDTFI.get_SortableDateTimePattern(), "(SortableDateTimePattern)");
        Console.WriteLine("  t     {0}", myDT.ToString("t"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_ShortTimePattern()
,
            "(ShortTimePattern)");
        Console.WriteLine("  T     {0}", myDT.ToString("T"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_LongTimePattern(),
 
            "(LongTimePattern)");
        Console.WriteLine("  u     {0}", myDT.ToString("u"));
        Console.WriteLine("        {0} {1}\n", 
            myDTFI.get_UniversalSortableDateTimePattern(), 
            "(UniversalSortableDateTimePattern)");
        Console.WriteLine("  U     {0}\n", myDT.ToString("U"));
        Console.WriteLine("  y     {0}", myDT.ToString("y"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_YearMonthPattern()
,
            "(YearMonthPattern)");
        Console.WriteLine("  Y     {0}", myDT.ToString("Y"));
        Console.WriteLine("        {0} {1}\n", myDTFI.get_YearMonthPattern()
,
            "(YearMonthPattern)");
    } //main 
} //SamplesDTFI

/*
This code produces the following output.

FORMAT  en-US EXAMPLE
CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY

  d     1/3/2002
        M/d/yyyy (ShortDatePattern)

  D     Thursday, January 03, 2002
        dddd, MMMM dd, yyyy (LongDatePattern)

  f     Thursday, January 03, 2002 12:00 AM

  F     Thursday, January 03, 2002 12:00:00 AM
        dddd, MMMM dd, yyyy h:mm:ss tt (FullDateTimePattern)

  g     1/3/2002 12:00 AM

  G     1/3/2002 12:00:00 AM

  m     January 03
        MMMM dd (MonthDayPattern)

  M     January 03
        MMMM dd (MonthDayPattern)

  r     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  R     Thu, 03 Jan 2002 00:00:00 GMT
        ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (RFC1123Pattern)

  s     2002-01-03T00:00:00
        yyyy'-'MM'-'dd'T'HH':'mm':'ss (SortableDateTimePattern)

  t     12:00 AM
        h:mm tt (ShortTimePattern)

  T     12:00:00 AM
        h:mm:ss tt (LongTimePattern)

  u     2002-01-03 00:00:00Z
        yyyy'-'MM'-'dd HH':'mm':'ss'Z' (UniversalSortableDateTimePattern)

  U     Thursday, January 03, 2002 8:00:00 AM

  y     January, 2002
        MMMM, yyyy (YearMonthPattern)

  Y     January, 2002
        MMMM, yyyy (YearMonthPattern)
*/
継承階層継承階層
System.Object
  System.Globalization.DateTimeFormatInfo
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DateTimeFormatInfo クラス」の関連用語

DateTimeFormatInfo クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DateTimeFormatInfo クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS