TimeSpan.TryParseExact メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
時間間隔の文字列形式を等価の TimeSpan に変換し、変換に成功したかどうかを示す値を返します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。
オーバーロード
TryParseExact(String, String, IFormatProvider, TimeSpanStyles, TimeSpan) |
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、時間間隔の文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。 |
TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, TimeSpanStyles, TimeSpan) |
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、時間間隔の指定したスパン表現を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。 |
TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, TimeSpanStyles, TimeSpan) |
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、指定した時間間隔のスパン表現を等価の TimeSpan に変換し、変換に成功したかどうかを示す値を返します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。 |
TryParseExact(String, String[], IFormatProvider, TimeSpan) |
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の指定した文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。 |
TryParseExact(String, String[], IFormatProvider, TimeSpanStyles, TimeSpan) |
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、時間間隔の指定した文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。 |
TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, TimeSpan) |
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の指定したスパン表現を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。 |
TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, TimeSpan) |
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の指定したスパン表現を等価の TimeSpan に変換します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。 |
TryParseExact(String, String, IFormatProvider, TimeSpan) |
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。 |
TryParseExact(String, String, IFormatProvider, TimeSpanStyles, TimeSpan)
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、時間間隔の文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。
public:
static bool TryParseExact(System::String ^ input, System::String ^ format, IFormatProvider ^ formatProvider, System::Globalization::TimeSpanStyles styles, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (string input, string format, IFormatProvider formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
public static bool TryParseExact (string? input, string? format, IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
public static bool TryParseExact (string? input, string format, IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
static member TryParseExact : string * string * IFormatProvider * System.Globalization.TimeSpanStyles * TimeSpan -> bool
Public Shared Function TryParseExact (input As String, format As String, formatProvider As IFormatProvider, styles As TimeSpanStyles, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- String
変換する時間間隔を指定する文字列。
- format
- String
input
で必要とされる書式を定義する標準またはカスタムの書式指定文字列。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- styles
- TimeSpanStyles
input
のスタイルを示す 1 つ以上の列挙値。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
例
次の例では、 メソッドを使用して、さまざまな書式指定文字列とカルチャを使用して、時間間隔 ParseExact(String, String, IFormatProvider) のいくつかの文字列表現を解析します。 また、 値を使用 TimeSpanStyles.AssumeNegative して、各文字列を負の時間間隔として解釈します。 この例の出力は、カスタム書式指定文字列で使用されている場合にのみ、スタイルが戻り値に影響 TimeSpanStyles.AssumeNegative を与える方法を示しています。
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string intervalString, format;
TimeSpan interval;
CultureInfo culture = null;
// Parse hour:minute value with custom format specifier.
intervalString = "17:14";
format = "h\\:mm";
culture = CultureInfo.CurrentCulture;
if (TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse hour:minute:second value with "g" specifier.
intervalString = "17:14:48";
format = "g";
culture = CultureInfo.InvariantCulture;
if (TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse hours:minute.second value with custom format specifier.
intervalString = "17:14:48.153";
format = @"h\:mm\:ss\.fff";
culture = null;
if (TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse days:hours:minute.second value with "G" specifier
// and current (en-US) culture.
intervalString = "3:17:14:48.153";
format = "G";
culture = CultureInfo.CurrentCulture;
if (TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse days:hours:minute.second value with a custom format specifier.
intervalString = "3:17:14:48.153";
format = @"d\:hh\:mm\:ss\.fff";
culture = null;
if (TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse days:hours:minute.second value with "G" specifier
// and fr-FR culture.
intervalString = "3:17:14:48,153";
format = "G";
culture = new CultureInfo("fr-FR");
if (TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse a single number using the "c" standard format string.
intervalString = "12";
format = "c";
if (TimeSpan.TryParseExact(intervalString, format,
null, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse a single number using the "%h" custom format string.
format = "%h";
if (TimeSpan.TryParseExact(intervalString, format,
null, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
// Parse a single number using the "%s" custom format string.
format = "%s";
if (TimeSpan.TryParseExact(intervalString, format,
null, TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval);
else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format);
}
}
// The example displays the following output:
// '17:14' (h\:mm) --> -17:14:00
// '17:14:48' (g) --> 17:14:48
// '17:14:48.153' (h\:mm\:ss\.fff) --> -17:14:48.1530000
// '3:17:14:48.153' (G) --> 3.17:14:48.1530000
// '3:17:14:48.153' (d\:hh\:mm\:ss\.fff) --> -3.17:14:48.1530000
// '3:17:14:48,153' (G) --> 3.17:14:48.1530000
// '12' (c) --> 12.00:00:00
// '12' (%h) --> -12:00:00
// '12' (%s) --> -00:00:12
Imports System.Globalization
Module Example
Public Sub Main()
Dim intervalString, format As String
Dim interval As TimeSpan
Dim culture As CultureInfo = Nothing
' Parse hour:minute value with custom format specifier.
intervalString = "17:14"
format = "h\:mm"
culture = CultureInfo.CurrentCulture
If TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse hour:minute:second value with "g" specifier.
intervalString = "17:14:48"
format = "g"
culture = CultureInfo.InvariantCulture
If TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse hours:minute.second value with custom format specifier.
intervalString = "17:14:48.153"
format = "h\:mm\:ss\.fff"
culture = Nothing
If TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse days:hours:minute.second value with "G" specifier
' and current (en-US) culture.
intervalString = "3:17:14:48.153"
format = "G"
culture = CultureInfo.CurrentCulture
If TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse days:hours:minute.second value with a custom format specifier.
intervalString = "3:17:14:48.153"
format = "d\:hh\:mm\:ss\.fff"
culture = Nothing
If TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse days:hours:minute.second value with "G" specifier
' and fr-FR culture.
intervalString = "3:17:14:48,153"
format = "G"
culture = New CultureInfo("fr-FR")
If TimeSpan.TryParseExact(intervalString, format,
culture, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse a single number using the "c" standard format string.
intervalString = "12"
format = "c"
If TimeSpan.TryParseExact(intervalString, format,
Nothing, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse a single number using the "%h" custom format string.
format = "%h"
If TimeSpan.TryParseExact(intervalString, format,
Nothing, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
' Parse a single number using the "%s" custom format string.
format = "%s"
If TimeSpan.TryParseExact(intervalString, format,
Nothing, TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("'{0}' ({1}) --> {2}", intervalString, format, interval)
Else
Console.WriteLine("Unable to parse '{0}' using format {1}",
intervalString, format)
End If
End Sub
End Module
' The example displays the following output:
' '17:14' (h\:mm) --> -17:14:00
' '17:14:48' (g) --> 17:14:48
' '17:14:48.153' (h\:mm\:ss\.fff) --> -17:14:48.1530000
' '3:17:14:48.153' (G) --> 3.17:14:48.1530000
' '3:17:14:48.153' (d\:hh\:mm\:ss\.fff) --> -3.17:14:48.1530000
' '3:17:14:48,153' (G) --> 3.17:14:48.1530000
' '12' (c) --> 12.00:00:00
' '12' (%h) --> -12:00:00
' '12' (%s) --> -00:00:12
注釈
メソッドは、先頭と末尾の空白文字が無視される点を除き、 パラメーターで定義された形式である必要がある時間間隔の文字列形式を TryParseExact(String, String, IFormatProvider, TimeSpanStyles, TimeSpan) format
解析します。 このメソッドは、 メソッドに似ていますが、変換が失敗した場合は ParseExact(String, String, IFormatProvider, TimeSpanStyles) 例外をスローしない点が除いてです。
パラメーターは、1 つの標準書式指定子、または の必須書式を定義する 1 つ以上のカスタム書式指定子を含む format
文字列です input
。 有効な書式指定文字列の詳細については、「 標準 TimeSpan 書式指定文字列」および「カスタム TimeSpan 書式指定文字列」 を参照してください。
パラメーターは、標準書式指定文字列の場合に、返される文字列の形式に関するカルチャ固有 formatProvider
IFormatProvider format
の情報を提供する実装です。 formatProvider
パラメーターには、次のいずれかを指定できます。
返 CultureInfo される文字列に書式設定規則を反映するカルチャを表す オブジェクト。 プロパティ DateTimeFormatInfo によって返される オブジェクト CultureInfo.DateTimeFormat は、返される文字列の書式設定を定義します。
返 DateTimeFormatInfo される文字列の書式設定を定義する オブジェクト。
インターフェイスを実装するカスタム IFormatProvider オブジェクト。 その IFormatProvider.GetFormat メソッドは、書式設定情報 DateTimeFormatInfo を提供する オブジェクトを返します。
が formatProvider
null
の場合、 DateTimeFormatInfo 現在のカルチャに関連付けられている オブジェクトが使用されます。
パラメーター styles
は、カスタム書式指定文字列を使用して解析された文字列の解釈に影響します。 負の符号 ( ) が存在する場合にのみ、負の時間間隔として解釈されるか、常に負の時間間隔 ( ) として解釈されるか input
TimeSpanStyles.None が決定されます TimeSpanStyles.AssumeNegative 。 が使用されていない場合、負の時間間隔を正常に解析するには、リテラルの負の符号記号 TimeSpanStyles.AssumeNegative format
\ ("-"など) を含める必要があります。
こちらもご覧ください
適用対象
TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, TimeSpanStyles, TimeSpan)
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、時間間隔の指定したスパン表現を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。
public:
static bool TryParseExact(ReadOnlySpan<char> input, cli::array <System::String ^> ^ formats, IFormatProvider ^ formatProvider, System::Globalization::TimeSpanStyles styles, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (ReadOnlySpan<char> input, string?[]? formats, IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
public static bool TryParseExact (ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
public static bool TryParseExact (ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
static member TryParseExact : ReadOnlySpan<char> * string[] * IFormatProvider * System.Globalization.TimeSpanStyles * TimeSpan -> bool
Public Shared Function TryParseExact (input As ReadOnlySpan(Of Char), formats As String(), formatProvider As IFormatProvider, styles As TimeSpanStyles, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- ReadOnlySpan<Char>
変換する時間間隔を表す文字を格納しているスパン。
- formats
- String[]
input
に許容される書式を定義する、標準またはカスタムの書式指定文字列の配列。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- styles
- TimeSpanStyles
input
のスタイルを示す 1 つ以上の列挙値。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
適用対象
TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, TimeSpanStyles, TimeSpan)
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、指定した時間間隔のスパン表現を等価の TimeSpan に変換し、変換に成功したかどうかを示す値を返します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。
public:
static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider ^ formatProvider, System::Globalization::TimeSpanStyles styles, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
public static bool TryParseExact (ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
static member TryParseExact : ReadOnlySpan<char> * ReadOnlySpan<char> * IFormatProvider * System.Globalization.TimeSpanStyles * TimeSpan -> bool
Public Shared Function TryParseExact (input As ReadOnlySpan(Of Char), format As ReadOnlySpan(Of Char), formatProvider As IFormatProvider, styles As TimeSpanStyles, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- ReadOnlySpan<Char>
変換する時間間隔を表す文字を格納しているスパン。
- format
- ReadOnlySpan<Char>
input
に許容される書式を定義する、標準またはカスタムの書式指定文字列を表す文字を格納しているスパン。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- styles
- TimeSpanStyles
input
のスタイルを示す 1 つ以上の列挙値。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
適用対象
TryParseExact(String, String[], IFormatProvider, TimeSpan)
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の指定した文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。
public:
static bool TryParseExact(System::String ^ input, cli::array <System::String ^> ^ formats, IFormatProvider ^ formatProvider, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (string input, string[] formats, IFormatProvider formatProvider, out TimeSpan result);
public static bool TryParseExact (string? input, string?[]? formats, IFormatProvider? formatProvider, out TimeSpan result);
public static bool TryParseExact (string? input, string[] formats, IFormatProvider? formatProvider, out TimeSpan result);
static member TryParseExact : string * string[] * IFormatProvider * TimeSpan -> bool
Public Shared Function TryParseExact (input As String, formats As String(), formatProvider As IFormatProvider, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- String
変換する時間間隔を指定する文字列。
- formats
- String[]
input
に許容される書式を定義する、標準またはカスタムの書式指定文字列の配列。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
例
次の例では、 TryParseExact(String, String[], IFormatProvider, TimeSpan) メソッドを呼び出して、文字列配列の各要素を値に変換 TimeSpan します。 この例では、フランス語 - フランス語 ("fr-FR") カルチャの書式規則を使用して文字列を解釈します。 文字列は、一般的な短い形式または一般的な long 形式で時間間隔を表します。
さらに、この例では、時間間隔の解析メソッドが 1 桁の数字を解釈する方法を変更します。 通常、1 桁の数字は、時間間隔の日数として解釈されます。 代わりに、カスタム %h
書式指定文字列を使用して、1 桁の数字を時間数として解釈します。 この変更を有効にするには、カスタム書式指定文字列の前に配列内の他の書式指定 %h
文字列を指定する必要 formats
があります。
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string[] inputs = { "3", "16:42", "1:6:52:35.0625",
"1:6:52:35,0625" };
string[] formats = { "g", "G", "%h"};
TimeSpan interval;
CultureInfo culture = new CultureInfo("fr-FR");
// Parse each string in inputs using formats and the fr-FR culture.
foreach (string input in inputs) {
if(TimeSpan.TryParseExact(input, formats, culture, out interval))
Console.WriteLine("{0} --> {1:c}", input, interval);
else
Console.WriteLine("Unable to parse {0}", input);
}
}
}
// The example displays the following output:
// 3 --> 03:00:00
// 16:42 --> 16:42:00
// Unable to parse 1:6:52:35.0625
// 1:6:52:35,0625 --> 1.06:52:35.0625000
Imports System.Globalization
Module Example
Public Sub Main()
Dim inputs() As String = { "3", "16:42", "1:6:52:35.0625",
"1:6:52:35,0625" }
Dim formats() As String = { "%h", "g", "G" }
Dim interval As TimeSpan
Dim culture As New CultureInfo("fr-FR")
' Parse each string in inputs using formats and the fr-FR culture.
For Each input As String In inputs
If TimeSpan.TryParseExact(input, formats, culture, interval) Then
Console.WriteLine("{0} --> {1:c}", input, interval)
Else
Console.WriteLine("Unable to parse {0}", input)
End If
Next
End Sub
End Module
' The example displays the following output:
' 3 --> 03:00:00
' 16:42 --> 16:42:00
' Unable to parse 1:6:52:35.0625
' 1:6:52:35,0625 --> 1.06:52:35.0625000
注釈
メソッドは、時間間隔の文字列表現を解析します。ただし、先頭と末尾の空白文字は無視される点を除き、 パラメーターで指定された書式指定文字列の 1 つで定義された形式である TryParseExact(String, String[], IFormatProvider, TimeSpan) formats
必要があります。 このメソッドは、 メソッドに似ていますが、変換が失敗した場合は ParseExact(String, String[], IFormatProvider) 例外をスローしない点が除いてです。
パラメーターは、要素が 1 つの標準書式指定子、または の必要な書式を定義する 1 つ以上のカスタム書式指定子で構成される文字列 formats
配列です input
。 有効な書式指定文字列の詳細については、「 標準 TimeSpan 書式指定文字列」および「カスタム TimeSpan 書式指定文字列」 を参照してください。 input
解析操作が成功するには、 が のメンバー formats
に正確に対応している必要があります。 解析操作では、配列内の最初の要素から始まる各要素との一致 input
formats
が試行されます。
重要
メソッドは、解析に使用される書式指定文字列が 、値が "g" または "G" の標準書式指定文字列である場合にのみ、 パラメーターで指定されたカルチャの規則 TryParseExact formatProvider
input
TimeSpan を使用します。 "c"、"t"、および "T" 標準書式指定文字列では、インバリアント カルチャの書式設定規則が使用されます。 カスタム書式指定文字列は、入力文字列の正確な形式を定義し、リテラル文字を使用して時間間隔のコンポーネントを分離します。
パラメーターは、解析に使用される書式指定文字列が標準書式指定文字列である場合に、返される文字列の形式に関するカルチャ固有の情報を提供 formatProvider
IFormatProvider input
する実装です。 formatProvider
パラメーターには、次のいずれかを指定できます。
返 CultureInfo される文字列に書式設定規則を反映するカルチャを表す オブジェクト。 プロパティ DateTimeFormatInfo によって返される オブジェクト CultureInfo.DateTimeFormat は、返される文字列の書式設定を定義します。
返 DateTimeFormatInfo される文字列の書式設定を定義する オブジェクト。
インターフェイスを実装するカスタム IFormatProvider オブジェクト。 その IFormatProvider.GetFormat メソッドは、書式設定情報 DateTimeFormatInfo を提供する オブジェクトを返します。
が formatProvider
null
の場合、 DateTimeFormatInfo 現在のカルチャに関連付けられている オブジェクトが使用されます。
こちらもご覧ください
適用対象
TryParseExact(String, String[], IFormatProvider, TimeSpanStyles, TimeSpan)
指定した書式、カルチャ固有の書式情報、およびスタイルを使用して、時間間隔の指定した文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。
public:
static bool TryParseExact(System::String ^ input, cli::array <System::String ^> ^ formats, IFormatProvider ^ formatProvider, System::Globalization::TimeSpanStyles styles, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (string input, string[] formats, IFormatProvider formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
public static bool TryParseExact (string? input, string?[]? formats, IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
public static bool TryParseExact (string? input, string[] formats, IFormatProvider? formatProvider, System.Globalization.TimeSpanStyles styles, out TimeSpan result);
static member TryParseExact : string * string[] * IFormatProvider * System.Globalization.TimeSpanStyles * TimeSpan -> bool
Public Shared Function TryParseExact (input As String, formats As String(), formatProvider As IFormatProvider, styles As TimeSpanStyles, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- String
変換する時間間隔を指定する文字列。
- formats
- String[]
input
に許容される書式を定義する、標準またはカスタムの書式指定文字列の配列。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- styles
- TimeSpanStyles
input
のスタイルを示す 1 つ以上の列挙値。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
例
次の例では、 TryParseExact(String, String[], IFormatProvider, TimeSpanStyles, TimeSpan) メソッドを呼び出して、文字列配列の各要素を値に変換 TimeSpan します。 文字列は、一般的な短い形式または一般的な long 形式で時間間隔を表します。
さらに、この例では、時間間隔の解析メソッドが 1 桁の数字を解釈する方法を変更します。 通常、1 桁の数字は、時間間隔の日数として解釈されます。 代わりに、カスタム %h
書式指定文字列を使用して、1 桁の数字を時間数として解釈します。 この変更を有効にするには、カスタム書式指定文字列の前に配列内の他の書式指定 %h
文字列を指定する必要 formats
があります。 また、出力から、この書式指定子を使用して文字列を解析する場合にのみ、メソッド呼び出しで指定されたフラグ TimeSpanStyles.AssumeNegative が使用されます。
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string[] inputs = { "3", "16:42", "1:6:52:35.0625",
"1:6:52:35,0625" };
string[] formats = { "%h", "g", "G" };
TimeSpan interval;
CultureInfo culture = new CultureInfo("fr-FR");
// Parse each string in inputs using formats and the fr-FR culture.
foreach (string input in inputs) {
if(TimeSpan.TryParseExact(input, formats, culture,
TimeSpanStyles.AssumeNegative, out interval))
Console.WriteLine("{0} --> {1:c}", input, interval);
else
Console.WriteLine("Unable to parse {0}", input);
}
}
}
// The example displays the following output:
// 3 --> -03:00:00
// 16:42 --> 16:42:00
// Unable to parse 1:6:52:35.0625
// 1:6:52:35,0625 --> 1.06:52:35.0625000
Imports System.Globalization
Module Example
Public Sub Main()
Dim inputs() As String = { "3", "16:42", "1:6:52:35.0625",
"1:6:52:35,0625" }
Dim formats() As String = { "%h", "g", "G" }
Dim interval As TimeSpan
Dim culture As New CultureInfo("de-DE")
' Parse each string in inputs using formats and the fr-FR culture.
For Each input As String In inputs
If TimeSpan.TryParseExact(input, formats, culture,
TimeSpanStyles.AssumeNegative, interval) Then
Console.WriteLine("{0} --> {1:c}", input, interval)
Else
Console.WriteLine("Unable to parse {0}", input)
End If
Next
End Sub
End Module
' The example displays the following output:
' 3 --> -03:00:00
' 16:42 --> 16:42:00
' Unable to parse 1:6:52:35.0625
' 1:6:52:35,0625 --> 1.06:52:35.0625000
注釈
メソッドは、時間間隔の文字列表現を解析します。ただし、先頭と末尾の空白文字は無視される点を除き、 パラメーターで指定された書式指定文字列の 1 つで定義された形式である TryParseExact(String, String[], IFormatProvider, TimeSpanStyles, TimeSpan) formats
必要があります。 このメソッドは、 メソッドに似ていますが、変換が失敗した場合は ParseExact(String, String[], IFormatProvider, TimeSpanStyles) 例外をスローしない点が除いてです。
パラメーターは、要素が 1 つの標準書式指定子、または の必要な書式を定義する 1 つ以上のカスタム書式指定子で構成される文字列 formats
配列です input
。 有効な書式指定文字列の詳細については、「 標準 TimeSpan 書式指定文字列」および「カスタム TimeSpan 書式指定文字列」 を参照してください。 input
解析操作が成功するには、 が のメンバー formats
に正確に対応している必要があります。 解析操作では、配列内の最初の要素から始まる各要素との一致 input
formats
が試行されます。
重要
メソッドは、解析に使用される書式指定文字列が 、値が "g" または "G" の標準書式指定文字列である場合にのみ、 パラメーターで指定されたカルチャの規則 ParseExact formatProvider
input
TimeSpan を使用します。 "c"、"t"、および "T" 標準書式指定文字列では、インバリアント カルチャの書式設定規則が使用されます。 カスタム書式指定文字列は、入力文字列の正確な形式を定義し、リテラル文字を使用して時間間隔のコンポーネントを分離します。
パラメーターは、解析に使用される書式指定文字列が標準書式指定文字列である場合に、返される文字列の形式に関するカルチャ固有の情報を提供 formatProvider
IFormatProvider input
する実装です。 formatProvider
パラメーターには、次のいずれかを指定できます。
返 CultureInfo される文字列に書式設定規則を反映するカルチャを表す オブジェクト。 プロパティ DateTimeFormatInfo によって返される オブジェクト CultureInfo.DateTimeFormat は、返される文字列の書式設定を定義します。
返 DateTimeFormatInfo される文字列の書式設定を定義する オブジェクト。
インターフェイスを実装するカスタム IFormatProvider オブジェクト。 その IFormatProvider.GetFormat メソッドは、書式設定情報 DateTimeFormatInfo を提供する オブジェクトを返します。
が formatProvider
null
の場合、 DateTimeFormatInfo 現在のカルチャに関連付けられている オブジェクトが使用されます。
パラメーター styles
は、カスタム書式指定文字列を使用して解析される文字列の解釈に影響します。 負の符号 ( ) が存在する場合にのみ、負の時間間隔として解釈されるか、常に負の時間間隔 ( ) として解釈されるか input
TimeSpanStyles.None が決定されます TimeSpanStyles.AssumeNegative 。 が使用されていない場合、負の時間間隔を正常に解析するには、リテラルの負の符号記号 TimeSpanStyles.AssumeNegative format
\ ("-"など) を含める必要があります。
こちらもご覧ください
適用対象
TryParseExact(ReadOnlySpan<Char>, String[], IFormatProvider, TimeSpan)
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の指定したスパン表現を等価の TimeSpan に変換します。 文字列形式の書式は、指定されたいずれかの書式と完全に一致する必要があります。
public:
static bool TryParseExact(ReadOnlySpan<char> input, cli::array <System::String ^> ^ formats, IFormatProvider ^ formatProvider, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (ReadOnlySpan<char> input, string?[]? formats, IFormatProvider? formatProvider, out TimeSpan result);
public static bool TryParseExact (ReadOnlySpan<char> input, string[] formats, IFormatProvider formatProvider, out TimeSpan result);
public static bool TryParseExact (ReadOnlySpan<char> input, string[] formats, IFormatProvider? formatProvider, out TimeSpan result);
static member TryParseExact : ReadOnlySpan<char> * string[] * IFormatProvider * TimeSpan -> bool
Public Shared Function TryParseExact (input As ReadOnlySpan(Of Char), formats As String(), formatProvider As IFormatProvider, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- ReadOnlySpan<Char>
変換する時間間隔を表す文字を格納しているスパン。
- formats
- String[]
input
に許容される書式を定義する、標準またはカスタムの書式指定文字列の配列。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
適用対象
TryParseExact(ReadOnlySpan<Char>, ReadOnlySpan<Char>, IFormatProvider, TimeSpan)
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の指定したスパン表現を等価の TimeSpan に変換します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。
public:
static bool TryParseExact(ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider ^ formatProvider, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider? formatProvider, out TimeSpan result);
public static bool TryParseExact (ReadOnlySpan<char> input, ReadOnlySpan<char> format, IFormatProvider formatProvider, out TimeSpan result);
static member TryParseExact : ReadOnlySpan<char> * ReadOnlySpan<char> * IFormatProvider * TimeSpan -> bool
Public Shared Function TryParseExact (input As ReadOnlySpan(Of Char), format As ReadOnlySpan(Of Char), formatProvider As IFormatProvider, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- ReadOnlySpan<Char>
変換する時間間隔を表す文字を格納しているスパン。
- format
- ReadOnlySpan<Char>
input
に許容される書式を定義する、標準またはカスタムの書式指定文字列を表す文字を格納しているスパン。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
適用対象
TryParseExact(String, String, IFormatProvider, TimeSpan)
指定した書式とカルチャ固有の書式情報を使用して、時間間隔の文字列形式を等価の TimeSpan に変換します。 文字列形式の書式は、指定した書式と完全に一致する必要があります。
public:
static bool TryParseExact(System::String ^ input, System::String ^ format, IFormatProvider ^ formatProvider, [Runtime::InteropServices::Out] TimeSpan % result);
public static bool TryParseExact (string input, string format, IFormatProvider formatProvider, out TimeSpan result);
public static bool TryParseExact (string? input, string? format, IFormatProvider? formatProvider, out TimeSpan result);
public static bool TryParseExact (string? input, string format, IFormatProvider? formatProvider, out TimeSpan result);
static member TryParseExact : string * string * IFormatProvider * TimeSpan -> bool
Public Shared Function TryParseExact (input As String, format As String, formatProvider As IFormatProvider, ByRef result As TimeSpan) As Boolean
パラメーター
- input
- String
変換する時間間隔を指定する文字列。
- format
- String
input
で必要とされる書式を定義する標準またはカスタムの書式指定文字列。
- formatProvider
- IFormatProvider
カルチャ固有の書式情報を提供するオブジェクト。
- result
- TimeSpan
このメソッドが返されるときに、input
で指定した時間間隔を表すオブジェクトを格納します。変換に失敗した場合は、Zero を格納します。 このパラメーターは初期化せずに渡されます。
戻り値
input
が正常に変換された場合は true
。それ以外の場合は false
。
例
次の例では、 メソッドを使用して、さまざまな書式指定文字列とカルチャを使用して、時間間隔 TryParseExact(String, String, IFormatProvider, TimeSpanStyles, TimeSpan) のいくつかの文字列表現を解析します。
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string intervalString, format;
TimeSpan interval;
CultureInfo culture;
// Parse hour:minute value with "g" specifier current culture.
intervalString = "17:14";
format = "g";
culture = CultureInfo.CurrentCulture;
if (TimeSpan.TryParseExact(intervalString, format, culture, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse hour:minute:second value with "G" specifier.
intervalString = "17:14:48";
format = "G";
culture = CultureInfo.InvariantCulture;
if (TimeSpan.TryParseExact(intervalString, format, culture, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse hours:minute.second value with "G" specifier
// and current (en-US) culture.
intervalString = "17:14:48.153";
format = "G";
culture = CultureInfo.CurrentCulture;
if (TimeSpan.TryParseExact(intervalString, format, culture, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse days:hours:minute.second value with "G" specifier
// and current (en-US) culture.
intervalString = "3:17:14:48.153";
format = "G";
culture = CultureInfo.CurrentCulture;
if (TimeSpan.TryParseExact(intervalString, format, culture, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse days:hours:minute.second value with "G" specifier
// and fr-FR culture.
intervalString = "3:17:14:48.153";
format = "G";
culture = new CultureInfo("fr-FR");
if (TimeSpan.TryParseExact(intervalString, format, culture, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse days:hours:minute.second value with "G" specifier
// and fr-FR culture.
intervalString = "3:17:14:48,153";
format = "G";
if (TimeSpan.TryParseExact(intervalString, format, culture, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse a single number using the "c" standard format string.
intervalString = "12";
format = "c";
if (TimeSpan.TryParseExact(intervalString, format, null, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse a single number using the "%h" custom format string.
format = "%h";
if (TimeSpan.TryParseExact(intervalString, format, null, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
// Parse a single number using the "%s" custom format string.
format = "%s";
if (TimeSpan.TryParseExact(intervalString, format, null, out interval))
Console.WriteLine("'{0}' --> {1}", intervalString, interval);
else
Console.WriteLine("Unable to parse {0}", intervalString);
}
}
// The example displays the following output:
// '17:14' --> 17:14:00
// Unable to parse 17:14:48
// Unable to parse 17:14:48.153
// '3:17:14:48.153' --> 3.17:14:48.1530000
// Unable to parse 3:17:14:48.153
// '3:17:14:48,153' --> 3.17:14:48.1530000
// '12' --> 12.00:00:00
// '12' --> 12:00:00
// '12' --> 00:00:12
Imports System.Globalization
Module Example
Public Sub Main()
Dim intervalString, format As String
Dim interval As TimeSpan
Dim culture As CultureInfo
' Parse hour:minute value with "g" specifier current culture.
intervalString = "17:14"
format = "g"
culture = CultureInfo.CurrentCulture
If TimeSpan.TryParseExact(intervalString, format, culture, interval) Then
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse hour:minute:second value with "G" specifier.
intervalString = "17:14:48"
format = "G"
culture = CultureInfo.InvariantCulture
If TimeSpan.TryParseExact(intervalString, format, culture, interval) Then
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse hours:minute.second value with "G" specifier
' and current (en-US) culture.
intervalString = "17:14:48.153"
format = "G"
culture = CultureInfo.CurrentCulture
If TimeSpan.TryParseExact(intervalString, format, culture, interval) Then
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse days:hours:minute.second value with "G" specifier
' and current (en-US) culture.
intervalString = "3:17:14:48.153"
format = "G"
culture = CultureInfo.CurrentCulture
If TimeSpan.TryParseExact(intervalString, format, culture, interval) Then
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse days:hours:minute.second value with "G" specifier
' and fr-FR culture.
intervalString = "3:17:14:48.153"
format = "G"
culture = New CultureInfo("fr-FR")
If TimeSpan.TryParseExact(intervalString, format, culture, interval) Then
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse days:hours:minute.second value with "G" specifier
' and fr-FR culture.
intervalString = "3:17:14:48,153"
format = "G"
culture = New CultureInfo("fr-FR")
If TimeSpan.TryParseExact(intervalString, format, culture, interval) Then
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse a single number using the "c" standard format string.
intervalString = "12"
format = "c"
If TimeSpan.TryParseExact(intervalString, format, Nothing, interval)
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse a single number using the "%h" custom format string.
format = "%h"
If TimeSpan.TryParseExact(intervalString, format, Nothing, interval)
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
' Parse a single number using the "%s" custom format string.
format = "%s"
If TimeSpan.TryParseExact(intervalString, format, Nothing, interval) Then
Console.WriteLine("'{0}' --> {1}", intervalString, interval)
Else
Console.WriteLine("Unable to parse {0}", intervalString)
End If
End Sub
End Module
' The example displays the following output:
' '17:14' --> 17:14:00
' Unable to parse 17:14:48
' Unable to parse 17:14:48.153
' '3:17:14:48.153' --> 3.17:14:48.1530000
' Unable to parse 3:17:14:48.153
' '3:17:14:48,153' --> 3.17:14:48.1530000
' '12' --> 12.00:00:00
' '12' --> 12:00:00
' '12' --> 00:00:12
注釈
メソッドは、先頭と末尾の空白文字が無視される点を除き、 パラメーターで定義された形式である必要がある時間間隔の文字列形式を TryParseExact(String, String, IFormatProvider, TimeSpan) format
解析します。 このメソッドは、 メソッドに似ていますが、変換が失敗した場合は ParseExact(String, String, IFormatProvider) 例外をスローしない点が除いてです。
パラメーターは、1 つの標準書式指定子、または の必須書式を定義する 1 つ以上のカスタム書式指定子を含む format
文字列です input
。 有効な書式指定文字列の詳細については、「 標準 TimeSpan 書式指定文字列」および「カスタム TimeSpan 書式指定文字列」 を参照してください。
重要
メソッドは、値が "g" または "G" の標準書式指定文字列である場合にのみ、 パラメーターで指定されたカルチャの規則 TryParseExact(String, String, IFormatProvider, TimeSpan) formatProvider
format
TimeSpan を使用します。 "c"、"t"、および "T" 標準書式指定文字列では、インバリアント カルチャの書式設定規則が使用されます。 カスタム書式指定文字列は、入力文字列の正確な形式を定義し、リテラル文字を使用して時間間隔のコンポーネントを分離します。
パラメーターは、標準書式指定文字列の場合に、返される文字列の形式に関するカルチャ固有 formatProvider
IFormatProvider format
の情報を提供する実装です。 formatProvider
パラメーターには、次のいずれかを指定できます。
返 CultureInfo される文字列に書式設定規則を反映するカルチャを表す オブジェクト。 プロパティ DateTimeFormatInfo によって返される オブジェクト CultureInfo.DateTimeFormat は、返される文字列の書式設定を定義します。
返 DateTimeFormatInfo される文字列の書式設定を定義する オブジェクト。
インターフェイスを実装するカスタム IFormatProvider オブジェクト。 その IFormatProvider.GetFormat メソッドは、書式設定情報 DateTimeFormatInfo を提供する オブジェクトを返します。
が formatProvider
null
の場合、 DateTimeFormatInfo 現在のカルチャに関連付けられている オブジェクトが使用されます。