DateTime.ParseExact メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DateTime.ParseExact メソッドの意味・解説 

DateTime.ParseExact メソッド (String, String[], IFormatProvider, DateTimeStyles)

指定した書式配列、カルチャ固有の書式情報、およびスタイル使用して指定した日付と時刻文字列形式等価DateTime変換します文字列形式書式は、指定した書式少なくとも 1 つ完全に一致する必要があります

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

Public Shared Function ParseExact
 ( _
    s As String, _
    formats As String(), _
    provider As IFormatProvider, _
    style As DateTimeStyles _
) As DateTime
Dim s As String
Dim formats As String()
Dim provider As IFormatProvider
Dim style As DateTimeStyles
Dim returnValue As DateTime

returnValue = DateTime.ParseExact(s, formats, provider, style)
public static DateTime ParseExact (
    string s,
    string[] formats,
    IFormatProvider provider,
    DateTimeStyles style
)
public:
static DateTime ParseExact (
    String^ s, 
    array<String^>^ formats, 
    IFormatProvider^ provider, 
    DateTimeStyles style
)
public static DateTime ParseExact (
    String s, 
    String[] formats, 
    IFormatProvider provider, 
    DateTimeStyles style
)
public static function ParseExact
 (
    s : String, 
    formats : String[], 
    provider : IFormatProvider, 
    style : DateTimeStyles
) : DateTime

パラメータ

s

変換する 1 つ上の日付と時刻格納した文字列

formats

s必要な書式配列

provider

s に関するカルチャ固有の書式情報提供する IFormatProvider。

style

s使用可能な書式を示す、DateTimeStyles 値のビットごとの組み合わせ通常指定する値は、None です。

戻り値
formatsprovider、および style指定されたとおりの、s格納されている日付と時刻等価DateTime

例外例外
例外種類条件

ArgumentNullException

s または formatsnull 参照 (Visual Basic では Nothing) です。

FormatException

s空の文字列です。

または

formats要素空の文字列です。

または

s に、formatsいずれか要素対応する日付と時刻格納されていません。

ArgumentException

style に、無効な DateTimeStyles 値の組み合わせ指定されています。たとえば、AssumeLocal と AssumeUniversal の両方指定した場合、この例外発生します

解説解説

s パラメータには、解析対象日付と時刻指定しますs パラメータ時刻だけを指定して日付指定しない場合現在の日付使用するか、既定日付使用するかが、style パラメータによって決定されます。s パラメータ日付だけを指定して時刻指定しない場合は、深夜 (00:00:00) が使用されます。また、s パラメータ先頭内部、または末尾空白文字含めることができるかどうかstyle パラメータによって決定されます。

format パラメータには、s パラメータ適切な形式整形するためのパターン配列指定しますformat パラメータ指定するパターンにはカスタム書式指定子 (カスタム DateTime 書式指定文字列 の表を参照) を 1 つまたは複数使用したり、標準的な定義済みパターン (標準DateTime 書式指定文字列 の表を参照) を単独使用したできます

カスタム書式パターン日付または時刻区切り記号指定しない場合は、provider パラメータにインバリアント カルチャを指定し、各カスタム書式指定子に最も広義形式使用します。たとえば、パターン時間指定する場合狭義形式 "H" ではなく広義形式 "HH" を指定します

provider パラメータには、特定の言語における週の曜日名や、月、日、年の表記順序など、カルチャ固有の日時形式情報指定しますformat パラメータには、通常、CultureInfo オブジェクト表されるカルチャを指定しますprovidernull 参照 (Visual Basic では Nothing) の場合は、現在のカルチャが使用されます。

使用例使用例

ParseExact メソッドコード例次に示します

Imports System
Imports System.Globalization

Class Class1
   Public Shared Sub Main()
      ' Assume the current culture is en-US. 
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim myDateTimeValue As String
 = "2/16/1992 12:15:12"
      Dim myDateTime As DateTime = DateTime.Parse(myDateTimeValue)
      Console.WriteLine("1) myDateTime       = {0}",
 myDateTime)
      
      ' Reverse month and day to conform to a different culture.
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim culture = New CultureInfo("fr-FR",
 True)
      Dim myDateTimeFrenchValue As String
 = "    16/02/1992 12:15:12"
      Dim myDateTimeFrench As DateTime = _
                           DateTime.Parse(myDateTimeFrenchValue, _
                                          culture, _
                                          DateTimeStyles.NoCurrentDateDefault)
      Console.WriteLine("2) myDateTimeFrench = {0}",
 myDateTimeFrench)
      
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim expectedFormats As String()
 =  {"G", "g", "f",
 "F"}
      myDateTimeFrench = DateTime.ParseExact(myDateTimeFrenchValue, _
                                          expectedFormats, _
                                          culture, _
                                          DateTimeStyles.AllowWhiteSpaces)
      Console.WriteLine("3) myDateTimeFrench = {0}",
 myDateTimeFrench)
   End Sub 'Main
End Class 'Class1
'
'This example yields the following results:
'
'1) myDateTime       = 2/16/1992 12:15:12 PM
'2) myDateTimeFrench = 2/16/1992 12:15:12 PM
'3) myDateTimeFrench = 2/16/1992 12:15:12 PM
'
using System;
using System.Globalization;

namespace Parse
{
    class Class1
    {
        public static void
 Main(string[] args)
        {
// Assume the current culture is en-US. 
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        string myDateTimeValue = "2/16/1992 12:15:12";
        DateTime myDateTime = DateTime.Parse(myDateTimeValue);
        Console.WriteLine("1) myDateTime       = {0}", myDateTime);

// Reverse month and day to conform to a different culture.
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        IFormatProvider culture = new CultureInfo("fr-FR",
 true);
        string myDateTimeFrenchValue = "    16/02/1992 12:15:12";
        DateTime myDateTimeFrench =
            DateTime.Parse(myDateTimeFrenchValue,
                           culture,
                           DateTimeStyles.NoCurrentDateDefault);
        Console.WriteLine("2) myDateTimeFrench = {0}", myDateTimeFrench);
    
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        string[] expectedFormats = {"G", "g",
 "f" ,"F"};
        myDateTimeFrench = 
                DateTime.ParseExact(myDateTimeFrenchValue,
                                    expectedFormats,
                                    culture,
                                    DateTimeStyles.AllowWhiteSpaces);
        Console.WriteLine("3) myDateTimeFrench = {0}", myDateTimeFrench);
        }
    }
}
/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Assume the current culture is en-US.
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   String^ myDateTimeValue = "2/16/1992 12:15:12";
   DateTime myDateTime = DateTime::Parse( myDateTimeValue );
   Console::WriteLine( "1) myDateTime       = {0}", myDateTime );
   
   // Reverse month and day to conform to a different culture.
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   IFormatProvider^ culture = gcnew CultureInfo( "fr-FR",true
 );
   String^ myDateTimeFrenchValue = "    16/02/1992 12:15:12";
   DateTime myDateTimeFrench = DateTime::Parse( myDateTimeFrenchValue, culture, DateTimeStyles::NoCurrentDateDefault
 );
   Console::WriteLine( "2) myDateTimeFrench = {0}", myDateTimeFrench );
   
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   array<String^>^expectedFormats = {"G","g","f"
,"F"};
   myDateTimeFrench = DateTime::ParseExact( myDateTimeFrenchValue, expectedFormats,
 culture, DateTimeStyles::AllowWhiteSpaces );
   Console::WriteLine( "3) myDateTimeFrench = {0}", myDateTimeFrench );
}

/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
package Parse; 

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

class Class1
{
    public static void main(String[]
 args)
    {
        // Assume the current culture is en-US. 
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        String myDateTimeValue = "2/16/1992 12:15:12";
        DateTime myDateTime = DateTime.Parse(myDateTimeValue);
        Console.WriteLine("1) myDateTime       = {0}", myDateTime);
        // Reverse month and day to conform to a different culture.
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        IFormatProvider culture = new CultureInfo("fr-FR",
 true);
        String myDateTimeFrenchValue = "    16/02/1992 12:15:12";
        DateTime myDateTimeFrench = DateTime.Parse(myDateTimeFrenchValue, 
            culture, DateTimeStyles.NoCurrentDateDefault);
        Console.WriteLine("2) myDateTimeFrench = {0}", myDateTimeFrench);
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        String expectedFormats[] =  { "G", "g", "f",
 "F" };
        myDateTimeFrench = DateTime.ParseExact(myDateTimeFrenchValue, 
            expectedFormats, culture, DateTimeStyles.AllowWhiteSpaces);
        Console.WriteLine("3) myDateTimeFrench = {0}", myDateTimeFrench);
    } //main
} //Class1
/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime.ParseExact メソッド (String, String, IFormatProvider, DateTimeStyles)

指定した書式、カルチャ固有の書式情報、およびスタイル使用して指定した日付と時刻文字列形式等価DateTime変換します文字列形式書式は、指定した書式完全に一致する必要があります

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

Public Shared Function ParseExact
 ( _
    s As String, _
    format As String, _
    provider As IFormatProvider, _
    style As DateTimeStyles _
) As DateTime
Dim s As String
Dim format As String
Dim provider As IFormatProvider
Dim style As DateTimeStyles
Dim returnValue As DateTime

returnValue = DateTime.ParseExact(s, format, provider, style)
public static DateTime ParseExact (
    string s,
    string format,
    IFormatProvider provider,
    DateTimeStyles style
)
public:
static DateTime ParseExact (
    String^ s, 
    String^ format, 
    IFormatProvider^ provider, 
    DateTimeStyles style
)
public static DateTime ParseExact (
    String s, 
    String format, 
    IFormatProvider provider, 
    DateTimeStyles style
)
public static function ParseExact
 (
    s : String, 
    format : String, 
    provider : IFormatProvider, 
    style : DateTimeStyles
) : DateTime

パラメータ

s

変換する日付と時刻格納した文字列

format

s必要な書式

provider

s に関するカルチャに固有の書式情報提供する IFormatProvider。

style

s使用可能な書式を示す、DateTimeStyles 値のビットごとの組み合わせ通常指定する値は、None です。

戻り値
formatprovider、および style指定されたとおりの、s格納されている日付と時刻等価DateTime

例外例外
例外種類条件

ArgumentNullException

s または formatnull 参照 (Visual Basic では Nothing) です。

FormatException

s または format空の文字列です。

または

s に、format指定されパターン対応する日付と時刻格納されていません。

ArgumentException

style に、無効な DateTimeStyles 値の組み合わせ指定されています。たとえば、AssumeLocal と AssumeUniversal の両方指定した場合、この例外発生します

解説解説

s パラメータには、解析対象日付と時刻指定しますs パラメータ時刻だけを指定して日付指定しない場合現在の日付使用するか、既定日付使用するかが、style パラメータによって決定されます。s パラメータ日付だけを指定して時刻指定しない場合は、深夜 (00:00:00) が使用されます。また、s パラメータ先頭内部、または末尾空白文字含めることができるかどうかstyle パラメータによって決定されます。

format パラメータには、s パラメータ適切な形式整形するためのパターン指定しますformat パラメータ指定するパターンにはカスタム書式指定子 (カスタム DateTime 書式指定文字列 の表を参照) を 1 つまたは複数使用したり、標準的な定義済みパターン (標準DateTime 書式指定文字列 の表を参照) を単独使用したできます

カスタム書式パターン日付または時刻区切り記号指定しない場合は、provider パラメータにインバリアント カルチャを指定し、各カスタム書式指定子に最も広義形式使用します。たとえば、パターン時間指定する場合狭義形式 "H" ではなく広義形式 "HH" を指定します

provider パラメータには、特定の言語における週の曜日名や、月、日、年の表記順序など、カルチャ固有の日時形式情報指定しますformat パラメータには、通常、CultureInfo オブジェクト表されるカルチャを指定しますprovidernull 参照 (Visual Basic では Nothing) の場合は、現在のカルチャが使用されます。

使用例使用例

ParseExact メソッドコード例次に示します

Imports System
Imports System.Globalization

Class Class1
   Public Shared Sub Main()
      ' Assume the current culture is en-US. 
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim myDateTimeValue As String
 = "2/16/1992 12:15:12"
      Dim myDateTime As DateTime = DateTime.Parse(myDateTimeValue)
      Console.WriteLine("1) myDateTime       = {0}",
 myDateTime)
      
      ' Reverse month and day to conform to a different culture.
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim culture = New CultureInfo("fr-FR",
 True)
      Dim myDateTimeFrenchValue As String
 = "    16/02/1992 12:15:12"
      Dim myDateTimeFrench As DateTime = _
                           DateTime.Parse(myDateTimeFrenchValue, _
                                          culture, _
                                          DateTimeStyles.NoCurrentDateDefault)
      Console.WriteLine("2) myDateTimeFrench = {0}",
 myDateTimeFrench)
      
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim expectedFormats As String()
 =  {"G", "g", "f",
 "F"}
      myDateTimeFrench = DateTime.ParseExact(myDateTimeFrenchValue, _
                                          expectedFormats, _
                                          culture, _
                                          DateTimeStyles.AllowWhiteSpaces)
      Console.WriteLine("3) myDateTimeFrench = {0}",
 myDateTimeFrench)
   End Sub 'Main
End Class 'Class1
'
'This example yields the following results:
'
'1) myDateTime       = 2/16/1992 12:15:12 PM
'2) myDateTimeFrench = 2/16/1992 12:15:12 PM
'3) myDateTimeFrench = 2/16/1992 12:15:12 PM
'
using System;
using System.Globalization;

namespace Parse
{
    class Class1
    {
        public static void
 Main(string[] args)
        {
// Assume the current culture is en-US. 
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        string myDateTimeValue = "2/16/1992 12:15:12";
        DateTime myDateTime = DateTime.Parse(myDateTimeValue);
        Console.WriteLine("1) myDateTime       = {0}", myDateTime);

// Reverse month and day to conform to a different culture.
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        IFormatProvider culture = new CultureInfo("fr-FR",
 true);
        string myDateTimeFrenchValue = "    16/02/1992 12:15:12";
        DateTime myDateTimeFrench =
            DateTime.Parse(myDateTimeFrenchValue,
                           culture,
                           DateTimeStyles.NoCurrentDateDefault);
        Console.WriteLine("2) myDateTimeFrench = {0}", myDateTimeFrench);
    
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        string[] expectedFormats = {"G", "g",
 "f" ,"F"};
        myDateTimeFrench = 
                DateTime.ParseExact(myDateTimeFrenchValue,
                                    expectedFormats,
                                    culture,
                                    DateTimeStyles.AllowWhiteSpaces);
        Console.WriteLine("3) myDateTimeFrench = {0}", myDateTimeFrench);
        }
    }
}
/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Assume the current culture is en-US.
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   String^ myDateTimeValue = "2/16/1992 12:15:12";
   DateTime myDateTime = DateTime::Parse( myDateTimeValue );
   Console::WriteLine( "1) myDateTime       = {0}", myDateTime );
   
   // Reverse month and day to conform to a different culture.
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   IFormatProvider^ culture = gcnew CultureInfo( "fr-FR",true
 );
   String^ myDateTimeFrenchValue = "    16/02/1992 12:15:12";
   DateTime myDateTimeFrench = DateTime::Parse( myDateTimeFrenchValue, culture, DateTimeStyles::NoCurrentDateDefault
 );
   Console::WriteLine( "2) myDateTimeFrench = {0}", myDateTimeFrench );
   
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   array<String^>^expectedFormats = {"G","g","f"
,"F"};
   myDateTimeFrench = DateTime::ParseExact( myDateTimeFrenchValue, expectedFormats,
 culture, DateTimeStyles::AllowWhiteSpaces );
   Console::WriteLine( "3) myDateTimeFrench = {0}", myDateTimeFrench );
}

/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
package Parse; 

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

class Class1
{
    public static void main(String[]
 args)
    {
        // Assume the current culture is en-US. 
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        String myDateTimeValue = "2/16/1992 12:15:12";
        DateTime myDateTime = DateTime.Parse(myDateTimeValue);
        Console.WriteLine("1) myDateTime       = {0}", myDateTime);
        // Reverse month and day to conform to a different culture.
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        IFormatProvider culture = new CultureInfo("fr-FR",
 true);
        String myDateTimeFrenchValue = "    16/02/1992 12:15:12";
        DateTime myDateTimeFrench = DateTime.Parse(myDateTimeFrenchValue, 
            culture, DateTimeStyles.NoCurrentDateDefault);
        Console.WriteLine("2) myDateTimeFrench = {0}", myDateTimeFrench);
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        String expectedFormats[] =  { "G", "g", "f",
 "F" };
        myDateTimeFrench = DateTime.ParseExact(myDateTimeFrenchValue, 
            expectedFormats, culture, DateTimeStyles.AllowWhiteSpaces);
        Console.WriteLine("3) myDateTimeFrench = {0}", myDateTimeFrench);
    } //main
} //Class1
/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DateTime.ParseExact メソッド

指定した文字列形式日付と時刻等価DateTime の値に変換します文字列形式書式は、指定した書式完全に一致する必要があります
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

DateTime 構造体
DateTime メンバ
System 名前空間
Parse
String
CultureInfo
CurrentInfo

その他の技術情報

書式設定概要
日付と時刻書式指定文字列

DateTime.ParseExact メソッド (String, String, IFormatProvider)

指定した書式とカルチャ固有の書式情報使用して指定した日付と時刻文字列形式等価DateTime の値に変換します文字列形式書式は、指定した書式完全に一致する必要があります

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

Public Shared Function ParseExact
 ( _
    s As String, _
    format As String, _
    provider As IFormatProvider _
) As DateTime
Dim s As String
Dim format As String
Dim provider As IFormatProvider
Dim returnValue As DateTime

returnValue = DateTime.ParseExact(s, format, provider)
public static DateTime ParseExact (
    string s,
    string format,
    IFormatProvider provider
)
public:
static DateTime ParseExact (
    String^ s, 
    String^ format, 
    IFormatProvider^ provider
)
public static DateTime ParseExact (
    String s, 
    String format, 
    IFormatProvider provider
)
public static function ParseExact
 (
    s : String, 
    format : String, 
    provider : IFormatProvider
) : DateTime

パラメータ

s

変換する日付と時刻格納した文字列

format

s必要な書式

provider

s に関するカルチャ固有の書式情報提供する IFormatProvider。

戻り値
formatprovider指定されたとおりの、s格納されている日付と時刻等価DateTime

例外例外
例外種類条件

ArgumentNullException

s または formatnull 参照 (Visual Basic では Nothing) です。

FormatException

s または format空の文字列です。

または

s に、format指定されパターン対応する日付と時刻格納されていません。

解説解説

s パラメータには、解析対象日付と時刻指定しますs時刻だけを指定して日付指定しない場合は、現在の日付使用されます。s パラメータ日付だけを指定して時刻指定しない場合は、深夜 (00:00:00) が使用されます。s パラメータ先頭内部、または末尾空白文字含めることはできません。

format パラメータには、s パラメータ適切な形式整形するためのパターン指定しますformat パラメータ指定するパターンにはカスタム書式指定子 (カスタム DateTime 書式指定文字列 の表を参照) を 1 つまたは複数使用したり、標準的な定義済みパターン (標準DateTime 書式指定文字列 の表を参照) を単独使用したできます

カスタム書式パターン日付または時刻区切り記号指定しない場合は、provider パラメータにインバリアント カルチャを指定し、各カスタム書式指定子に最も広義形式使用します。たとえば、パターン時間指定する場合狭義形式 "H" ではなく広義形式 "HH" を指定します

provider パラメータには、特定の言語における週の曜日名や、月、日、年の表記順序など、カルチャ固有の日時形式情報指定しますformat パラメータには、通常、CultureInfo オブジェクト表されるカルチャを指定しますprovidernull 参照 (Visual Basic では Nothing) の場合は、現在のカルチャが使用されます。

使用例使用例

ParseExact メソッドコード例次に示します

Imports System
Imports System.Globalization

Class Class1
   Public Shared Sub Main()
      ' Assume the current culture is en-US. 
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim myDateTimeValue As String
 = "2/16/1992 12:15:12"
      Dim myDateTime As DateTime = DateTime.Parse(myDateTimeValue)
      Console.WriteLine("1) myDateTime       = {0}",
 myDateTime)
      
      ' Reverse month and day to conform to a different culture.
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim culture = New CultureInfo("fr-FR",
 True)
      Dim myDateTimeFrenchValue As String
 = "    16/02/1992 12:15:12"
      Dim myDateTimeFrench As DateTime = _
                           DateTime.Parse(myDateTimeFrenchValue, _
                                          culture, _
                                          DateTimeStyles.NoCurrentDateDefault)
      Console.WriteLine("2) myDateTimeFrench = {0}",
 myDateTimeFrench)
      
      ' The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

      Dim expectedFormats As String()
 =  {"G", "g", "f",
 "F"}
      myDateTimeFrench = DateTime.ParseExact(myDateTimeFrenchValue, _
                                          expectedFormats, _
                                          culture, _
                                          DateTimeStyles.AllowWhiteSpaces)
      Console.WriteLine("3) myDateTimeFrench = {0}",
 myDateTimeFrench)
   End Sub 'Main
End Class 'Class1
'
'This example yields the following results:
'
'1) myDateTime       = 2/16/1992 12:15:12 PM
'2) myDateTimeFrench = 2/16/1992 12:15:12 PM
'3) myDateTimeFrench = 2/16/1992 12:15:12 PM
'
using System;
using System.Globalization;

namespace Parse
{
    class Class1
    {
        public static void
 Main(string[] args)
        {
// Assume the current culture is en-US. 
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        string myDateTimeValue = "2/16/1992 12:15:12";
        DateTime myDateTime = DateTime.Parse(myDateTimeValue);
        Console.WriteLine("1) myDateTime       = {0}", myDateTime);

// Reverse month and day to conform to a different culture.
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        IFormatProvider culture = new CultureInfo("fr-FR",
 true);
        string myDateTimeFrenchValue = "    16/02/1992 12:15:12";
        DateTime myDateTimeFrench =
            DateTime.Parse(myDateTimeFrenchValue,
                           culture,
                           DateTimeStyles.NoCurrentDateDefault);
        Console.WriteLine("2) myDateTimeFrench = {0}", myDateTimeFrench);
    
// The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.

        string[] expectedFormats = {"G", "g",
 "f" ,"F"};
        myDateTimeFrench = 
                DateTime.ParseExact(myDateTimeFrenchValue,
                                    expectedFormats,
                                    culture,
                                    DateTimeStyles.AllowWhiteSpaces);
        Console.WriteLine("3) myDateTimeFrench = {0}", myDateTimeFrench);
        }
    }
}
/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Assume the current culture is en-US.
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   String^ myDateTimeValue = "2/16/1992 12:15:12";
   DateTime myDateTime = DateTime::Parse( myDateTimeValue );
   Console::WriteLine( "1) myDateTime       = {0}", myDateTime );
   
   // Reverse month and day to conform to a different culture.
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   IFormatProvider^ culture = gcnew CultureInfo( "fr-FR",true
 );
   String^ myDateTimeFrenchValue = "    16/02/1992 12:15:12";
   DateTime myDateTimeFrench = DateTime::Parse( myDateTimeFrenchValue, culture, DateTimeStyles::NoCurrentDateDefault
 );
   Console::WriteLine( "2) myDateTimeFrench = {0}", myDateTimeFrench );
   
   // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds.
   array<String^>^expectedFormats = {"G","g","f"
,"F"};
   myDateTimeFrench = DateTime::ParseExact( myDateTimeFrenchValue, expectedFormats,
 culture, DateTimeStyles::AllowWhiteSpaces );
   Console::WriteLine( "3) myDateTimeFrench = {0}", myDateTimeFrench );
}

/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
package Parse; 

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

class Class1
{
    public static void main(String[]
 args)
    {
        // Assume the current culture is en-US. 
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        String myDateTimeValue = "2/16/1992 12:15:12";
        DateTime myDateTime = DateTime.Parse(myDateTimeValue);
        Console.WriteLine("1) myDateTime       = {0}", myDateTime);
        // Reverse month and day to conform to a different culture.
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        IFormatProvider culture = new CultureInfo("fr-FR",
 true);
        String myDateTimeFrenchValue = "    16/02/1992 12:15:12";
        DateTime myDateTimeFrench = DateTime.Parse(myDateTimeFrenchValue, 
            culture, DateTimeStyles.NoCurrentDateDefault);
        Console.WriteLine("2) myDateTimeFrench = {0}", myDateTimeFrench);
        // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12
 seconds.
        String expectedFormats[] =  { "G", "g", "f",
 "F" };
        myDateTimeFrench = DateTime.ParseExact(myDateTimeFrenchValue, 
            expectedFormats, culture, DateTimeStyles.AllowWhiteSpaces);
        Console.WriteLine("3) myDateTimeFrench = {0}", myDateTimeFrench);
    } //main
} //Class1
/*
This example yields the following results:

1) myDateTime       = 2/16/1992 12:15:12 PM
2) myDateTimeFrench = 2/16/1992 12:15:12 PM
3) myDateTimeFrench = 2/16/1992 12:15:12 PM
*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「DateTime.ParseExact メソッド」の関連用語

DateTime.ParseExact メソッドのお隣キーワード
検索ランキング

   

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



DateTime.ParseExact メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS