DateTime.ToString 메서드
정의
오버로드
ToString(String, IFormatProvider) |
지정된 형식 및 문화권별 형식 정보를 사용하여 현재 DateTime 개체의 값을 해당 문자열 표현으로 변환합니다.Converts the value of the current DateTime object to its equivalent string representation using the specified format and culture-specific format information. |
ToString(String) |
현재 문화권의 형식 규칙과 지정된 형식을 사용하여 현재 DateTime 개체의 값을 해당하는 문자열 표현으로 변환합니다.Converts the value of the current DateTime object to its equivalent string representation using the specified format and the formatting conventions of the current culture. |
ToString(IFormatProvider) |
지정된 문화권별 형식 정보를 사용하여 현재 DateTime 개체의 값을 해당하는 문자열 표현으로 변환합니다.Converts the value of the current DateTime object to its equivalent string representation using the specified culture-specific format information. |
ToString() |
현재 문화권의 형식 규칙을 사용하여 현재 DateTime 개체의 값을 해당하는 문자열 표현으로 변환합니다.Converts the value of the current DateTime object to its equivalent string representation using the formatting conventions of the current culture. |
ToString(String, IFormatProvider)
public:
virtual System::String ^ ToString(System::String ^ format, IFormatProvider ^ provider);
public string ToString (string format, IFormatProvider provider);
public string ToString (string? format, IFormatProvider? provider);
override this.ToString : string * IFormatProvider -> string
Public Function ToString (format As String, provider As IFormatProvider) As String
매개 변수
- format
- String
표준 또는 사용자 지정 날짜 및 시간 서식 문자열입니다.A standard or custom date and time format string.
- provider
- IFormatProvider
문화권별 형식 정보를 제공하는 개체입니다.An object that supplies culture-specific formatting information.
반환
현재 DateTime 개체의 값을 format
및 provider
에 지정된 내용에 따라 나타낸 문자열 표현입니다.A string representation of value of the current DateTime object as specified by format
and provider
.
구현
예외
format
의 길이가 1이고 DateTimeFormatInfo에 대해 정의된 형식 지정자 문자 중 하나가 아닙니다.The length of format
is 1, and it is not one of the format specifier characters defined for DateTimeFormatInfo.
또는-or-
format
에 올바른 사용자 지정 형식 패턴이 포함되어 있지 않습니다.format
does not contain a valid custom format pattern.
날짜 및 시간이 provider
에서 사용되는 달력에서 지원하는 날짜 범위를 벗어납니다.The date and time is outside the range of dates supported by the calendar used by provider
.
예제
다음 예제에서는 각각의 표준 날짜 시간 형식 문자열을 사용 하 여 4 개의 서로 다른 문화권에 대 한 날짜 및 시간의 문자열 표현을 표시 합니다.The following example uses each of the standard date time format strings to display the string representation of a date and time for four different cultures.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
// Create an array of all supported standard date and time format specifiers.
string[] formats = {"d", "D", "f", "F", "g", "G", "m", "o", "r",
"s", "t", "T", "u", "U", "Y"};
// Create an array of four cultures.
CultureInfo[] cultures = {CultureInfo.CreateSpecificCulture("de-DE"),
CultureInfo.CreateSpecificCulture("en-US"),
CultureInfo.CreateSpecificCulture("es-ES"),
CultureInfo.CreateSpecificCulture("fr-FR")};
// Define date to be displayed.
DateTime dateToDisplay = new DateTime(2008, 10, 31, 17, 4, 32);
// Iterate each standard format specifier.
foreach (string formatSpecifier in formats)
{
foreach (CultureInfo culture in cultures)
Console.WriteLine("{0} Format Specifier {1, 10} Culture {2, 40}",
formatSpecifier, culture.Name,
dateToDisplay.ToString(formatSpecifier, culture));
Console.WriteLine();
}
}
}
// The example displays the following output:
// d Format Specifier de-DE Culture 31.10.2008
// d Format Specifier en-US Culture 10/31/2008
// d Format Specifier es-ES Culture 31/10/2008
// d Format Specifier fr-FR Culture 31/10/2008
//
// D Format Specifier de-DE Culture Freitag, 31. Oktober 2008
// D Format Specifier en-US Culture Friday, October 31, 2008
// D Format Specifier es-ES Culture viernes, 31 de octubre de 2008
// D Format Specifier fr-FR Culture vendredi 31 octobre 2008
//
// f Format Specifier de-DE Culture Freitag, 31. Oktober 2008 17:04
// f Format Specifier en-US Culture Friday, October 31, 2008 5:04 PM
// f Format Specifier es-ES Culture viernes, 31 de octubre de 2008 17:04
// f Format Specifier fr-FR Culture vendredi 31 octobre 2008 17:04
//
// F Format Specifier de-DE Culture Freitag, 31. Oktober 2008 17:04:32
// F Format Specifier en-US Culture Friday, October 31, 2008 5:04:32 PM
// F Format Specifier es-ES Culture viernes, 31 de octubre de 2008 17:04:32
// F Format Specifier fr-FR Culture vendredi 31 octobre 2008 17:04:32
//
// g Format Specifier de-DE Culture 31.10.2008 17:04
// g Format Specifier en-US Culture 10/31/2008 5:04 PM
// g Format Specifier es-ES Culture 31/10/2008 17:04
// g Format Specifier fr-FR Culture 31/10/2008 17:04
//
// G Format Specifier de-DE Culture 31.10.2008 17:04:32
// G Format Specifier en-US Culture 10/31/2008 5:04:32 PM
// G Format Specifier es-ES Culture 31/10/2008 17:04:32
// G Format Specifier fr-FR Culture 31/10/2008 17:04:32
//
// m Format Specifier de-DE Culture 31. Oktober
// m Format Specifier en-US Culture October 31
// m Format Specifier es-ES Culture 31 de octubre
// m Format Specifier fr-FR Culture 31 octobre
//
// o Format Specifier de-DE Culture 2008-10-31T17:04:32.0000000
// o Format Specifier en-US Culture 2008-10-31T17:04:32.0000000
// o Format Specifier es-ES Culture 2008-10-31T17:04:32.0000000
// o Format Specifier fr-FR Culture 2008-10-31T17:04:32.0000000
//
// r Format Specifier de-DE Culture Fri, 31 Oct 2008 17:04:32 GMT
// r Format Specifier en-US Culture Fri, 31 Oct 2008 17:04:32 GMT
// r Format Specifier es-ES Culture Fri, 31 Oct 2008 17:04:32 GMT
// r Format Specifier fr-FR Culture Fri, 31 Oct 2008 17:04:32 GMT
//
// s Format Specifier de-DE Culture 2008-10-31T17:04:32
// s Format Specifier en-US Culture 2008-10-31T17:04:32
// s Format Specifier es-ES Culture 2008-10-31T17:04:32
// s Format Specifier fr-FR Culture 2008-10-31T17:04:32
//
// t Format Specifier de-DE Culture 17:04
// t Format Specifier en-US Culture 5:04 PM
// t Format Specifier es-ES Culture 17:04
// t Format Specifier fr-FR Culture 17:04
//
// T Format Specifier de-DE Culture 17:04:32
// T Format Specifier en-US Culture 5:04:32 PM
// T Format Specifier es-ES Culture 17:04:32
// T Format Specifier fr-FR Culture 17:04:32
//
// u Format Specifier de-DE Culture 2008-10-31 17:04:32Z
// u Format Specifier en-US Culture 2008-10-31 17:04:32Z
// u Format Specifier es-ES Culture 2008-10-31 17:04:32Z
// u Format Specifier fr-FR Culture 2008-10-31 17:04:32Z
//
// U Format Specifier de-DE Culture Freitag, 31. Oktober 2008 09:04:32
// U Format Specifier en-US Culture Friday, October 31, 2008 9:04:32 AM
// U Format Specifier es-ES Culture viernes, 31 de octubre de 2008 9:04:32
// U Format Specifier fr-FR Culture vendredi 31 octobre 2008 09:04:32
//
// Y Format Specifier de-DE Culture Oktober 2008
// Y Format Specifier en-US Culture October 2008
// Y Format Specifier es-ES Culture octubre de 2008
// Y Format Specifier fr-FR Culture octobre 2008
Imports System.Globalization
Module Example
Public Sub Main()
' Create an array of all supported standard date and time format specifiers.
Dim formats() As String = {"d", "D", "f", "F", "g", "G", "m", "o", "r", _
"s", "t", "T", "u", "U", "Y"}
' Create an array of four cultures.
Dim cultures() As CultureInfo = {CultureInfo.CreateSpecificCulture("de-DE"), _
CultureInfo.CreateSpecificCulture("en-US"), _
CultureInfo.CreateSpecificCulture("es-ES"), _
CultureInfo.CreateSpecificCulture("fr-FR")}
' Define date to be displayed.
Dim dateToDisplay As Date = #10/1/2008 17:04:32#
' Iterate each standard format specifier.
For Each formatSpecifier As String In formats
For Each culture As CultureInfo In cultures
Console.WriteLine("{0} Format Specifier {1, 10} Culture {2, 40}", _
formatSpecifier, culture.Name, _
dateToDisplay.ToString(formatSpecifier, culture))
Next
Console.WriteLine()
Next
End Sub
End Module
' The example displays the following output:
' d Format Specifier de-DE Culture 01.10.2008
' d Format Specifier en-US Culture 10/1/2008
' d Format Specifier es-ES Culture 01/10/2008
' d Format Specifier fr-FR Culture 01/10/2008
'
' D Format Specifier de-DE Culture Mittwoch, 1. Oktober 2008
' D Format Specifier en-US Culture Wednesday, October 01, 2008
' D Format Specifier es-ES Culture miércoles, 01 de octubre de 2008
' D Format Specifier fr-FR Culture mercredi 1 octobre 2008
'
' f Format Specifier de-DE Culture Mittwoch, 1. Oktober 2008 17:04
' f Format Specifier en-US Culture Wednesday, October 01, 2008 5:04 PM
' f Format Specifier es-ES Culture miércoles, 01 de octubre de 2008 17:04
' f Format Specifier fr-FR Culture mercredi 1 octobre 2008 17:04
'
' F Format Specifier de-DE Culture Mittwoch, 1. Oktober 2008 17:04:32
' F Format Specifier en-US Culture Wednesday, October 01, 2008 5:04:32 PM
' F Format Specifier es-ES Culture miércoles, 01 de octubre de 2008 17:04:3
' F Format Specifier fr-FR Culture mercredi 1 octobre 2008 17:04:32
'
' g Format Specifier de-DE Culture 01.10.2008 17:04
' g Format Specifier en-US Culture 10/1/2008 5:04 PM
' g Format Specifier es-ES Culture 01/10/2008 17:04
' g Format Specifier fr-FR Culture 01/10/2008 17:04
'
' G Format Specifier de-DE Culture 01.10.2008 17:04:32
' G Format Specifier en-US Culture 10/1/2008 5:04:32 PM
' G Format Specifier es-ES Culture 01/10/2008 17:04:32
' G Format Specifier fr-FR Culture 01/10/2008 17:04:32
'
' m Format Specifier de-DE Culture 01 Oktober
' m Format Specifier en-US Culture October 01
' m Format Specifier es-ES Culture 01 octubre
' m Format Specifier fr-FR Culture 1 octobre
'
' o Format Specifier de-DE Culture 2008-10-01T17:04:32.0000000
' o Format Specifier en-US Culture 2008-10-01T17:04:32.0000000
' o Format Specifier es-ES Culture 2008-10-01T17:04:32.0000000
' o Format Specifier fr-FR Culture 2008-10-01T17:04:32.0000000
'
' r Format Specifier de-DE Culture Wed, 01 Oct 2008 17:04:32 GMT
' r Format Specifier en-US Culture Wed, 01 Oct 2008 17:04:32 GMT
' r Format Specifier es-ES Culture Wed, 01 Oct 2008 17:04:32 GMT
' r Format Specifier fr-FR Culture Wed, 01 Oct 2008 17:04:32 GMT
'
' s Format Specifier de-DE Culture 2008-10-01T17:04:32
' s Format Specifier en-US Culture 2008-10-01T17:04:32
' s Format Specifier es-ES Culture 2008-10-01T17:04:32
' s Format Specifier fr-FR Culture 2008-10-01T17:04:32
'
' t Format Specifier de-DE Culture 17:04
' t Format Specifier en-US Culture 5:04 PM
' t Format Specifier es-ES Culture 17:04
' t Format Specifier fr-FR Culture 17:04
'
' T Format Specifier de-DE Culture 17:04:32
' T Format Specifier en-US Culture 5:04:32 PM
' T Format Specifier es-ES Culture 17:04:32
' T Format Specifier fr-FR Culture 17:04:32
'
' u Format Specifier de-DE Culture 2008-10-01 17:04:32Z
' u Format Specifier en-US Culture 2008-10-01 17:04:32Z
' u Format Specifier es-ES Culture 2008-10-01 17:04:32Z
' u Format Specifier fr-FR Culture 2008-10-01 17:04:32Z
'
' U Format Specifier de-DE Culture Donnerstag, 2. Oktober 2008 00:04:32
' U Format Specifier en-US Culture Thursday, October 02, 2008 12:04:32 AM
' U Format Specifier es-ES Culture jueves, 02 de octubre de 2008 0:04:32
' U Format Specifier fr-FR Culture jeudi 2 octobre 2008 00:04:32
'
' Y Format Specifier de-DE Culture Oktober 2008
' Y Format Specifier en-US Culture October, 2008
' Y Format Specifier es-ES Culture octubre de 2008
' Y Format Specifier fr-FR Culture octobre 2008
다음 예제에서는 DateTime 고정을 사용 하 여 값의 서식을 지정 하는 다양 한 방법을 보여 줍니다 DateTimeFormatInfo .The following example demonstrates different ways of formatting a DateTime value using the invariant DateTimeFormatInfo.
using namespace System;
using namespace System::Globalization;
void main()
{
DateTime dt = DateTime::Now;
array<String^>^format = {L"d",L"D",L"f",L"F",L"g",L"G",L"m",L"r",L"s",L"t",L"T",L"u",L"U",L"y",L"dddd, MMMM dd yyyy",L"ddd, MMM d \"'\"yy",L"dddd, MMMM dd",L"M/yy",L"dd-MM-yy"};
String^ date;
for ( int i = 0; i < format->Length; i++ )
{
date = dt.ToString( format[ i ], DateTimeFormatInfo::InvariantInfo );
Console::WriteLine( String::Concat( format[ i ], L" :", date ) );
}
/** Output.
*
* d :08/17/2000
* D :Thursday, August 17, 2000
* f :Thursday, August 17, 2000 16:32
* F :Thursday, August 17, 2000 16:32:32
* g :08/17/2000 16:32
* G :08/17/2000 16:32:32
* m :August 17
* r :Thu, 17 Aug 2000 23:32:32 GMT
* s :2000-08-17T16:32:32
* t :16:32
* T :16:32:32
* u :2000-08-17 23:32:32Z
* U :Thursday, August 17, 2000 23:32:32
* y :August, 2000
* dddd, MMMM dd yyyy :Thursday, August 17 2000
* ddd, MMM d "'"yy :Thu, Aug 17 '00
* dddd, MMMM dd :Thursday, August 17
* M/yy :8/00
* dd-MM-yy :17-08-00
*/
}
using System;
using System.Globalization;
public class MainClass {
public static void Main(string[] args) {
DateTime dt = DateTime.Now;
String[] format = {
"d", "D",
"f", "F",
"g", "G",
"m",
"r",
"s",
"t", "T",
"u", "U",
"y",
"dddd, MMMM dd yyyy",
"ddd, MMM d \"'\"yy",
"dddd, MMMM dd",
"M/yy",
"dd-MM-yy",
};
String date;
for (int i = 0; i < format.Length; i++) {
date = dt.ToString(format[i], DateTimeFormatInfo.InvariantInfo);
Console.WriteLine(String.Concat(format[i], " :" , date));
}
/** Output.
*
* d :08/17/2000
* D :Thursday, August 17, 2000
* f :Thursday, August 17, 2000 16:32
* F :Thursday, August 17, 2000 16:32:32
* g :08/17/2000 16:32
* G :08/17/2000 16:32:32
* m :August 17
* r :Thu, 17 Aug 2000 23:32:32 GMT
* s :2000-08-17T16:32:32
* t :16:32
* T :16:32:32
* u :2000-08-17 23:32:32Z
* U :Thursday, August 17, 2000 23:32:32
* y :August, 2000
* dddd, MMMM dd yyyy :Thursday, August 17 2000
* ddd, MMM d "'"yy :Thu, Aug 17 '00
* dddd, MMMM dd :Thursday, August 17
* M/yy :8/00
* dd-MM-yy :17-08-00
*/
}
}
Option Explicit
Option Strict
Imports System.Globalization
Public Class MainClass
Public Shared Sub Main()
Dim dt As DateTime = DateTime.Now
Dim myformat() As String = {"d", "D", _
"f", "F", _
"g", "G", _
"m", _
"r", _
"s", _
"t", "T", _
"u", "U", _
"y", _
"dddd, MMMM dd yyyy", _
"ddd, MMM d ""'""yy", _
"dddd, MMMM dd", _
"M/yy", _
"dd-MM-yy"}
Dim mydate As String
Dim i As Integer
For i = 0 To myformat.Length - 1
mydate = dt.ToString(myformat(i), DateTimeFormatInfo.InvariantInfo)
Console.WriteLine(String.Concat(myformat(i), " :", mydate))
Next i
' Output.
'
' d :08/17/2000
' D :Thursday, August 17, 2000
' f :Thursday, August 17, 2000 16:32
' F :Thursday, August 17, 2000 16:32:32
' g :08/17/2000 16:32
' G :08/17/2000 16:32:32
' m :August 17
' r :Thu, 17 Aug 2000 23:32:32 GMT
' s :2000-08-17T16:32:32
' t :16:32
' T :16:32:32
' u :2000-08-17 23:32:32Z
' U :Thursday, August 17, 2000 23:32:32
' y :August, 2000
' dddd, MMMM dd yyyy :Thursday, August 17 2000
' ddd, MMM d "'"yy :Thu, Aug 17 '00
' dddd, MMMM dd :Thursday, August 17
' M/yy :8/00
' dd-MM-yy :17-08-00
End Sub
End Class
설명
format
매개 변수는 단일 형식 지정자 문자 ( 표준 날짜 및 시간 형식 문자열참조) 또는 사용자 지정 형식 패턴 ( 사용자 지정 날짜 및 시간 형식 문자열참조) 중 하나를 포함할 수 있습니다.The format
parameter can contain either a single format specifier character (see Standard Date and Time Format Strings) or a custom format pattern (see Custom Date and Time Format Strings). format
이 null
이거나 빈 문자열 ("") 이면 표준 형식 지정자 "G"가 사용 됩니다.If format
is null
or an empty string (""), the standard format specifier, "G", is used.
provider
매개 변수는 표준 형식 지정자와 날짜 및 시간 구성 요소의 기호와 이름에 해당 하는 패턴을 정의 합니다.The provider
parameter defines the pattern that corresponds to the standard format specifiers, as well as the symbols and names of date and time components. provider
매개 변수는 다음 중 하나일 수 있습니다.The provider
parameter can be any of the following:
CultureInfo반환 되는 문자열에 반영 되는 형식 지정 규칙의 문화권을 나타내는 개체입니다.A CultureInfo object that represents the culture whose formatting conventions are to be reflected in the returned string. DateTimeFormatInfo속성에서 반환 되는 개체는 CultureInfo.DateTimeFormat 반환 된 문자열의 서식을 정의 합니다.The DateTimeFormatInfo object returned by the CultureInfo.DateTimeFormat property defines the formatting of the returned string.
DateTimeFormatInfo날짜 및 시간 데이터의 형식을 정의 하는 개체입니다.A DateTimeFormatInfo object that defines the format of date and time data.
인터페이스를 구현 하는 사용자 지정 개체 IFormatProvider 입니다.A custom object that implements the IFormatProvider interface. 해당 GetFormat 메서드는 DateTimeFormatInfo 형식 지정 정보를 제공 하는 개체를 반환 합니다.Its GetFormat method returns a DateTimeFormatInfo object that provides formatting information.
provider
가 이면 null
DateTimeFormatInfo 현재 문화권과 연결 된이 사용 됩니다.If provider
is null
, the DateTimeFormatInfo associated with the current culture is used. 자세한 내용은 CultureInfo.CurrentCulture를 참조하세요.For more information, see CultureInfo.CurrentCulture.
호출자 참고
ToString(String, IFormatProvider)메서드는 매개 변수에 사용 되는 달력의 날짜 및 시간에 대 한 문자열 표현을 반환 합니다 provider
.The ToString(String, IFormatProvider) method returns the string representation of the date and time in the calendar used by the provider
parameter. 해당 달력은 속성으로 정의 됩니다 Calendar .Its calendar is defined by the Calendar property. 현재 DateTime 인스턴스의 값이 보다 이전 이거나 이후 이면이 MinSupportedDateTime MaxSupportedDateTime 메서드는을 throw ArgumentOutOfRangeException 합니다.If the value of the current DateTime instance is earlier than MinSupportedDateTime or later than MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException. 다음 예제에서 이에 대해 설명합니다.The following example provides an illustration. 클래스의 범위를 벗어나는 날짜의 형식을 지정 하려고 UmAlQuraCalendar 합니다.It attempts to format a date that is outside the range of the UmAlQuraCalendar class.
::: code language = "csharp" source = "~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception4.cs" interactive = "try...catch" id = "Snippet4":::::: code language = "vb" source = "~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception4.vb" id = "Snippet4"::::::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception4.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception4.vb" id="Snippet4":::
추가 정보
- DateTimeFormatInfo
- CultureInfo
- .NET의 서식 지정 형식Formatting Types in .NET
- 표준 날짜 및 시간 형식 문자열Standard Date and Time Format Strings
- 사용자 지정 날짜 및 시간 형식 문자열Custom Date and Time Format Strings
- 샘플: .NET Core WinForms 서식 유틸리티(C#)Sample: .NET Core WinForms Formatting Utility (C#)
- 샘플: .NET Core WinForms 서식 유틸리티(Visual Basic)Sample: .NET Core WinForms Formatting Utility (Visual Basic)
적용 대상
ToString(String)
public:
System::String ^ ToString(System::String ^ format);
public string ToString (string format);
public string ToString (string? format);
override this.ToString : string -> string
Public Function ToString (format As String) As String
매개 변수
- format
- String
표준 또는 사용자 지정 날짜 및 시간 서식 문자열입니다.A standard or custom date and time format string.
반환
현재 DateTime 개체의 값을 format
에 지정된 내용에 따라 나타낸 문자열 표현입니다.A string representation of value of the current DateTime object as specified by format
.
예외
format
의 길이가 1이고 DateTimeFormatInfo에 대해 정의된 형식 지정자 문자 중 하나가 아닙니다.The length of format
is 1, and it is not one of the format specifier characters defined for DateTimeFormatInfo.
또는-or-
format
에 올바른 사용자 지정 형식 패턴이 포함되어 있지 않습니다.format
does not contain a valid custom format pattern.
날짜 및 시간이 현재 문화권에서 사용되는 달력에서 지원하는 날짜 범위를 벗어납니다.The date and time is outside the range of dates supported by the calendar used by the current culture.
예제
다음 예제에서는 각 표준 날짜 및 시간 서식 문자열과 사용자 지정 날짜 및 시간 형식 문자열을 사용 하 여 값의 문자열 표현을 표시 합니다 DateTime .The following example uses each of the standard date and time format strings and a selection of custom date and time format strings to display the string representation of a DateTime value. 예제에 대 한 스레드 현재 문화권이 en-us입니다.The thread current culture for the example is en-US.
using System;
public class DateToStringExample
{
public static void Main()
{
DateTime dateValue = new DateTime(2008, 6, 15, 21, 15, 07);
// Create an array of standard format strings.
string[] standardFmts = {"d", "D", "f", "F", "g", "G", "m", "o",
"R", "s", "t", "T", "u", "U", "y"};
// Output date and time using each standard format string.
foreach (string standardFmt in standardFmts)
Console.WriteLine("{0}: {1}", standardFmt,
dateValue.ToString(standardFmt));
Console.WriteLine();
// Create an array of some custom format strings.
string[] customFmts = {"h:mm:ss.ff t", "d MMM yyyy", "HH:mm:ss.f",
"dd MMM HH:mm:ss", @"\Mon\t\h\: M", "HH:mm:ss.ffffzzz" };
// Output date and time using each custom format string.
foreach (string customFmt in customFmts)
Console.WriteLine("'{0}': {1}", customFmt,
dateValue.ToString(customFmt));
}
}
// This example displays the following output to the console:
// d: 6/15/2008
// D: Sunday, June 15, 2008
// f: Sunday, June 15, 2008 9:15 PM
// F: Sunday, June 15, 2008 9:15:07 PM
// g: 6/15/2008 9:15 PM
// G: 6/15/2008 9:15:07 PM
// m: June 15
// o: 2008-06-15T21:15:07.0000000
// R: Sun, 15 Jun 2008 21:15:07 GMT
// s: 2008-06-15T21:15:07
// t: 9:15 PM
// T: 9:15:07 PM
// u: 2008-06-15 21:15:07Z
// U: Monday, June 16, 2008 4:15:07 AM
// y: June, 2008
//
// 'h:mm:ss.ff t': 9:15:07.00 P
// 'd MMM yyyy': 15 Jun 2008
// 'HH:mm:ss.f': 21:15:07.0
// 'dd MMM HH:mm:ss': 15 Jun 21:15:07
// '\Mon\t\h\: M': Month: 6
// 'HH:mm:ss.ffffzzz': 21:15:07.0000-07:00
Module DateToStringExample
Public Sub Main()
Dim dateValue As Date = #6/15/2008 9:15:07PM#
' Create an array of standard format strings.
Dim standardFmts() As String = {"d", "D", "f", "F", "g", "G", _
"m", "o", "R", "s", "t", "T", _
"u", "U", "y"}
' Output date and time using each standard format string.
For Each standardFmt As String In standardFmts
Console.WriteLine("{0}: {1}", standardFmt, _
dateValue.ToString(standardFmt))
Next
Console.WriteLine()
' Create an array of some custom format strings.
Dim customFmts() As String = {"h:mm:ss.ff t", "d MMM yyyy", "HH:mm:ss.f", _
"dd MMM HH:mm:ss", "\Mon\t\h\: M", "HH:mm:ss.ffffzzz" }
' Output date and time using each custom format string.
For Each customFmt As String In customFmts
Console.WriteLine("'{0}': {1}", customFmt, _
dateValue.ToString(customFmt))
Next
End Sub
End Module
' This example displays the following output to the console:
' d: 6/15/2008
' D: Sunday, June 15, 2008
' f: Sunday, June 15, 2008 9:15 PM
' F: Sunday, June 15, 2008 9:15:07 PM
' g: 6/15/2008 9:15 PM
' G: 6/15/2008 9:15:07 PM
' m: June 15
' o: 2008-06-15T21:15:07.0000000
' R: Sun, 15 Jun 2008 21:15:07 GMT
' s: 2008-06-15T21:15:07
' t: 9:15 PM
' T: 9:15:07 PM
' u: 2008-06-15 21:15:07Z
' U: Monday, June 16, 2008 4:15:07 AM
' y: June, 2008
'
' 'h:mm:ss.ff t': 9:15:07.00 P
' 'd MMM yyyy': 15 Jun 2008
' 'HH:mm:ss.f': 21:15:07.0
' 'dd MMM HH:mm:ss': 15 Jun 21:15:07
' '\Mon\t\h\: M': Month: 6
' 'HH:mm:ss.ffffzzz': 21:15:07.0000-07:00
설명
ToString(String)메서드는 현재 문화권의 서식 지정 규칙을 사용 하는 특정 형식으로 날짜 및 시간 값의 문자열 표현을 반환 합니다. 자세한 내용은를 참조 하십시오 CultureInfo.CurrentCulture .The ToString(String) method returns the string representation of a date and time value in a specific format that uses the formatting conventions of the current culture; for more information, see CultureInfo.CurrentCulture.
format
매개 변수는 반환 된 문자열의 형식을 정의 하는 단일 형식 지정자 문자 ( 표준 날짜 및 시간 형식 문자열참조) 또는 사용자 지정 형식 패턴 ( 사용자 지정 날짜 및 시간 형식 문자열참조) 중 하나를 포함 해야 합니다.The format
parameter should contain either a single format specifier character (see Standard Date and Time Format Strings) or a custom format pattern (see Custom Date and Time Format Strings) that defines the format of the returned string. format
이 null
또는 빈 문자열인 경우 일반 형식 지정자 ' G '가 사용 됩니다.If format
is null
or an empty string, the general format specifier, 'G', is used.
이 메서드의 몇 가지 용도는 다음과 같습니다.Some uses of this method include:
현재 문화권의 짧은 날짜 및 시간 형식으로 날짜와 시간을 표시 하는 문자열을 가져옵니다.Getting a string that displays the date and time in the current culture's short date and time format. 이렇게 하려면 "G" 서식 지정자를 사용 합니다.To do this, you use the "G" format specifier.
월과 연도만 포함 하는 문자열 가져오기Getting a string that contains only the month and year. 이렇게 하려면 "MM/yyyy" 형식 문자열을 사용 합니다.To do this, you use the "MM/yyyy" format string. 서식 문자열은 현재 문화권의 날짜 구분 기호를 사용 합니다.The format string uses the current culture's date separator.
특정 형식의 날짜 및 시간을 포함 하는 문자열을 가져옵니다.Getting a string that contains the date and time in a specific format. 예를 들어 "MM/dd/yyyyHH: MM" 형식 문자열은 날짜 및 시간 문자열을 "19//03//2013 18:06"와 같이 고정 된 형식으로 표시 합니다.For example, the "MM/dd/yyyyHH:mm" format string displays the date and time string in a fixed format such as "19//03//2013 18:06". 서식 문자열은 문화권별 설정에 관계 없이 "/"를 고정 날짜 구분 기호로 사용 합니다.The format string uses "/" as a fixed date separator regardless of culture-specific settings.
날짜 문자열을 직렬화 하는 데 사용할 수 있는 압축 형식으로 날짜를 가져옵니다.Getting a date in a condensed format that could be used for serializing a date string. 예를 들어, "yyyyMMdd" 형식 문자열은 네 자리 연도와 두 자리 월을 표시 하 고 날짜 구분 기호가 없는 두 자리 날짜를 표시 합니다.For example, the "yyyyMMdd" format string displays a four-digit year followed by a two-digit month and a two-digit day with no date separator.
다음 예제에서는 이러한 세 가지 형식 문자열을 사용 하 여 en-us 및 fr-fr 문화권의 규칙을 사용 하 여 날짜 및 시간 값을 표시 합니다.The following example uses these three format strings to display a date and time value by using the conventions of the en-US and fr-FR cultures.
using System;
using System.Globalization;
using System.Threading;
public class Example
{
public static void Main()
{
String[] formats = { "G", "MM/yyyy", @"MM\/dd\/yyyy HH:mm",
"yyyyMMdd" };
String[] cultureNames = { "en-US", "fr-FR" };
DateTime date = new DateTime(2015, 8, 18, 13, 31, 17);
foreach (var cultureName in cultureNames) {
var culture = new CultureInfo(cultureName);
CultureInfo.CurrentCulture = culture;
Console.WriteLine(culture.NativeName);
foreach (var format in formats)
Console.WriteLine(" {0}: {1}", format,
date.ToString(format));
Console.WriteLine();
}
}
}
// The example displays the following output:
// English (United States)
// G: 8/18/2015 1:31:17 PM
// MM/yyyy: 08/2015
// MM\/dd\/yyyy HH:mm: 08/18/2015 13:31
// yyyyMMdd: 20150818
//
// français (France)
// G: 18/08/2015 13:31:17
// MM/yyyy: 08/2015
// MM\/dd\/yyyy HH:mm: 08/18/2015 13:31
// yyyyMMdd: 20150818
Imports System.Globalization
Imports System.Threading
Public Module Example
Public Sub Main()
Dim formats() As String = { "G", "MM/yyyy", "MM\/dd\/yyyy HH:mm",
"yyyyMMdd" }
Dim cultureNames() As String = { "en-US", "fr-FR" }
Dim dat As New DateTime(2015, 8, 18, 13, 31, 17)
For Each cultureName In cultureNames
Dim culture As New CultureInfo(cultureName)
CultureInfo.CurrentCulture = culture
Console.WriteLine(culture.NativeName)
For Each fmt In formats
Console.WriteLine(" {0}: {1}", fmt,
dat.ToString(fmt))
Next
Console.WriteLine()
Next
End Sub
End Module
' The example displays the following output:
' English (United States)
' G: 8/18/2015 1:31:17 PM
' MM/yyyy: 08/2015
' MM\/dd\/yyyy HH:mm: 08/18/2015 13:31
' yyyyMMdd: 20150818
'
' français (France)
' G: 18/08/2015 13:31:17
' MM/yyyy: 08/2015
' MM\/dd\/yyyy HH:mm: 08/18/2015 13:31
' yyyyMMdd: 20150818
호출자 참고
ToString(String)메서드는 현재 문화권에서 사용 하는 달력의 날짜 및 시간에 대 한 문자열 표현을 반환 합니다.The ToString(String) method returns the string representation of the date and time in the calendar used by the current culture. 현재 DateTime 인스턴스의 값이 보다 이전 이거나 이후 이면이 MinSupportedDateTime MaxSupportedDateTime 메서드는을 throw ArgumentOutOfRangeException 합니다.If the value of the current DateTime instance is earlier than MinSupportedDateTime or later than MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException. 다음 예제에서 이에 대해 설명합니다.The following example provides an illustration. HebrewCalendar현재 문화권이 히브리어 (이스라엘) 일 때 클래스의 범위를 벗어나는 날짜의 형식을 지정 하려고 합니다.It attempts to format a date that is outside the range of the HebrewCalendar class when the current culture is Hebrew (Israel).
::: code language = "csharp" source = "~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception3.cs" interactive = "try...catch" id = "Snippet3":::::: code language = "vb" source = "~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception3.vb" id = "Snippet3"::::::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception3.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception3.vb" id="Snippet3":::
추가 정보
- DateTimeFormatInfo
- CultureInfo
- .NET의 서식 지정 형식Formatting Types in .NET
- 표준 날짜 및 시간 형식 문자열Standard Date and Time Format Strings
- 사용자 지정 날짜 및 시간 형식 문자열Custom Date and Time Format Strings
적용 대상
ToString(IFormatProvider)
public:
virtual System::String ^ ToString(IFormatProvider ^ provider);
public:
System::String ^ ToString(IFormatProvider ^ provider);
public string ToString (IFormatProvider provider);
public string ToString (IFormatProvider? provider);
override this.ToString : IFormatProvider -> string
Public Function ToString (provider As IFormatProvider) As String
매개 변수
- provider
- IFormatProvider
문화권별 형식 정보를 제공하는 개체입니다.An object that supplies culture-specific formatting information.
반환
현재 DateTime 개체의 값을 provider
에 지정된 내용에 따라 나타낸 문자열 표현입니다.A string representation of value of the current DateTime object as specified by provider
.
구현
예외
날짜 및 시간이 provider
에서 사용되는 달력에서 지원하는 날짜 범위를 벗어납니다.The date and time is outside the range of dates supported by the calendar used by provider
.
예제
다음 예제에서는 CultureInfo 5 개의 서로 다른 문화권을 나타내는 개체를 사용 하 여 날짜 및 시간의 문자열 표현을 표시 합니다.The following example displays the string representation of a date and time using CultureInfo objects that represent five different cultures.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
CultureInfo[] cultures = new CultureInfo[] {CultureInfo.InvariantCulture,
new CultureInfo("en-us"),
new CultureInfo("fr-fr"),
new CultureInfo("de-DE"),
new CultureInfo("es-ES"),
new CultureInfo("ja-JP")};
DateTime thisDate = new DateTime(2009, 5, 1, 9, 0, 0);
foreach (CultureInfo culture in cultures)
{
string cultureName;
if (string.IsNullOrEmpty(culture.Name))
cultureName = culture.NativeName;
else
cultureName = culture.Name;
Console.WriteLine("In {0}, {1}",
cultureName, thisDate.ToString(culture));
}
}
}
// The example produces the following output:
// In Invariant Language (Invariant Country), 05/01/2009 09:00:00
// In en-US, 5/1/2009 9:00:00 AM
// In fr-FR, 01/05/2009 09:00:00
// In de-DE, 01.05.2009 09:00:00
// In es-ES, 01/05/2009 9:00:00
// In ja-JP, 2009/05/01 9:00:00
Imports System.Globalization
Module Example
Public Sub Main()
Dim cultures() As CultureInfo = {CultureInfo.InvariantCulture, _
New CultureInfo("en-us"), _
New CultureInfo("fr-fr"), _
New CultureInfo("de-DE"), _
New CultureInfo("es-ES"), _
New CultureInfo("ja-JP")}
Dim thisDate As Date =#5/1/2009 9:00AM#
For Each culture As CultureInfo In cultures
Dim cultureName As String
If String.IsNullOrEmpty(culture.Name) Then
cultureName = culture.NativeName
Else
cultureName = culture.Name
End If
Console.WriteLine("In {0}, {1}", _
cultureName, thisDate.ToString(culture))
Next
End Sub
End Module
' The example produces the following output:
' In Invariant Language (Invariant Country), 05/01/2009 09:00:00
' In en-US, 5/1/2009 9:00:00 AM
' In fr-FR, 01/05/2009 09:00:00
' In de-DE, 01.05.2009 09:00:00
' In es-ES, 01/05/2009 9:00:00
' In ja-JP, 2009/05/01 9:00:00
설명
현재 개체의 값은 DateTime 일반 날짜 및 시간 형식 지정자 (' G ')를 사용 하 여 서식이 지정 됩니다 .이 지정자는 간단한 날짜 패턴과 긴 시간 패턴을 사용 하 여 출력 형식을 지정 합니다.The value of the current DateTime object is formatted using the general date and time format specifier ('G'), which formats output using the short date pattern and the long time pattern.
간단한 날짜 및 자세한 시간 패턴의 형식은 매개 변수에 의해 정의 됩니다 provider
.The format of the short date and long time pattern is defined by the provider
parameter. provider
매개 변수는 다음 중 하나일 수 있습니다.The provider
parameter can be any of the following:
CultureInfo반환 되는 문자열에 반영 되는 형식 지정 규칙의 문화권을 나타내는 개체입니다.A CultureInfo object that represents the culture whose formatting conventions are to be reflected in the returned string. DateTimeFormatInfo속성에서 반환 되는 개체는 CultureInfo.DateTimeFormat 반환 된 문자열의 서식을 정의 합니다.The DateTimeFormatInfo object returned by the CultureInfo.DateTimeFormat property defines the formatting of the returned string.
DateTimeFormatInfo날짜 및 시간 데이터의 형식을 정의 하는 개체입니다.A DateTimeFormatInfo object that defines the format of date and time data.
인터페이스를 구현 하는 사용자 지정 개체 IFormatProvider 입니다.A custom object that implements the IFormatProvider interface. 해당 GetFormat 메서드는 DateTimeFormatInfo 형식 지정 정보를 제공 하는 개체를 반환 합니다.Its GetFormat method returns a DateTimeFormatInfo object that provides formatting information.
provider
가 이면 null
DateTimeFormatInfo 현재 문화권과 연결 된 개체가 사용 됩니다.If provider
is null
, the DateTimeFormatInfo object associated with the current culture is used. 자세한 내용은 CultureInfo.CurrentCulture를 참조하세요.For more information, see CultureInfo.CurrentCulture.
호출자 참고
ToString(IFormatProvider)메서드는 매개 변수로 표시 되는 문화권에서 사용 하는 달력의 날짜 및 시간에 대 한 문자열 표현을 반환 합니다 provider
.The ToString(IFormatProvider) method returns the string representation of the date and time in the calendar used by the culture represented by the provider
parameter. 해당 달력은 속성으로 정의 됩니다 Calendar .Its calendar is defined by the Calendar property. 현재 DateTime 인스턴스의 값이 보다 이전 이거나 이후 이면이 MinSupportedDateTime MaxSupportedDateTime 메서드는을 throw ArgumentOutOfRangeException 합니다.If the value of the current DateTime instance is earlier than MinSupportedDateTime or later than MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException. 다음 예제에서 이에 대해 설명합니다.The following example provides an illustration. 클래스의 범위를 벗어나는 날짜의 형식을 지정 하려고 JapaneseCalendar 합니다.It attempts to format a date that is outside the range of the JapaneseCalendar class.
::: code language = "csharp" source = "~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception1.cs" interactive = "try...catch" id = "Snippet1":::::: code language = "vb" source = "~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception1.vb" id = "Snippet1"::::::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception1.vb" id="Snippet1":::
추가 정보
적용 대상
ToString()
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
반환
현재 DateTime 개체 값의 문자열 표현입니다.A string representation of the value of the current DateTime object.
예외
날짜 및 시간이 현재 문화권에서 사용되는 달력에서 지원하는 날짜 범위를 벗어납니다.The date and time is outside the range of dates supported by the calendar used by the current culture.
예제
다음 예제에서는 DateTime 메서드에서 반환 되는 값의 문자열 표현이 ToString() 스레드 현재 문화권에 따라 달라 지는 방식을 보여 줍니다.The following example illustrates how the string representation of a DateTime value returned by the ToString() method depends on the thread current culture. 현재 스레드 문화권을 en-us에서 fr-fr로 변경 합니다.It changes the current thread culture from en-US to fr-FR to ja-JP. 각 경우에서 메서드를 호출 ToString() 하 여 해당 문화권을 사용 하는 날짜 및 시간 값의 문자열 표현을 반환 합니다.and in each case calls the ToString() method to return the string representation of a date and time value using that culture.
using System;
using System.Globalization;
using System.Threading;
public class DateToStringExample
{
public static void Main()
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
DateTime exampleDate = new DateTime(2008, 5, 1, 18, 32, 6);
// Display the date using the current (en-US) culture.
Console.WriteLine(exampleDate.ToString());
// Change the current culture to fr-FR and display the date.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
Console.WriteLine(exampleDate.ToString());
// Change the current culture to ja-JP and display the date.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ja-JP");
Console.WriteLine(exampleDate.ToString());
// Restore the original culture
Thread.CurrentThread.CurrentCulture = currentCulture;
}
}
// The example displays the following output to the console:
// 5/1/2008 6:32:06 PM
// 01/05/2008 18:32:06
// 2008/05/01 18:32:06
Imports System.Globalization
Imports System.Threading
Module DateToStringExample
Public Sub Main()
Dim currentCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
Dim exampleDate As Date = #05/01/2008 6:32:06PM#
' Display the date using the current (en-US) culture.
Console.WriteLine(exampleDate.ToString())
' Change the current culture to fr-FR and display the date.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR")
Console.WriteLine(exampleDate.ToString())
' Change the current culture to ja-JP and display the date.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ja-JP")
Console.WriteLine(exampleDate.ToString())
' Restore the original culture
Thread.CurrentThread.CurrentCulture = currentCulture
End Sub
End Module
' The example displays the following output to the console:
' 5/1/2008 6:32:06 PM
' 01/05/2008 18:32:06
' 2008/05/01 18:32:06
설명
현재 개체의 값은 DateTime 일반 날짜 및 시간 형식 지정자 (' G ')를 사용 하 여 형식이 지정 됩니다.The value of the current DateTime object is formatted using the general date and time format specifier ('G'). 특정 날짜 및 시간 서식 지정자를 사용 하 여 형식을 지정 하려면 메서드를 호출 ToString(String) 합니다.To format it using a specific date and time format specifier, call the ToString(String) method. 특정 문화권에 대 한 일반 날짜 및 시간 형식 지정자 (' G ')를 사용 하 여 형식을 지정 하려면 ToString(IFormatProvider) 메서드를 호출 합니다.To format it using the general date and time format specifier ('G') for a specific culture, call the ToString(IFormatProvider) method. 특정 날짜 및 시간 형식 지정자 및 특정 문화권의 규칙을 사용 하 여 형식을 지정 하려면 메서드를 호출 ToString(String, IFormatProvider) 합니다.To format it using a specific date and time format specifier and the conventions of a specific culture, call the ToString(String, IFormatProvider) method.
이 메서드는 현재 문화권에서 파생 된 형식 지정 정보를 사용 합니다.This method uses formatting information derived from the current culture. 특히 속성에서 반환 하는 ShortDatePattern 개체의 및 속성에서 반환 하는 사용자 지정 형식 문자열을 결합 합니다 LongTimePattern DateTimeFormatInfo Thread.CurrentThread.CurrentCulture.DateTimeFormat
.In particular, it combines the custom format strings returned by the ShortDatePattern and LongTimePattern properties of the DateTimeFormatInfo object returned by the Thread.CurrentThread.CurrentCulture.DateTimeFormat
property. 자세한 내용은 CultureInfo.CurrentCulture를 참조하세요.For more information, see CultureInfo.CurrentCulture. 메서드의 다른 오버 로드를 사용 ToString 하 여 서식을 지정 하는 문화권을 지정 하 고 값의 출력 패턴을 정의할 수 있습니다 DateTime .Other overloads of the ToString method enable you to specify the culture whose formatting to use and to define the output pattern of the DateTime value.
호출자 참고
ToString()메서드는 현재 문화권에서 사용 하는 달력의 날짜 및 시간에 대 한 문자열 표현을 반환 합니다.The ToString() method returns the string representation of the date and time in the calendar used by the current culture. 현재 DateTime 인스턴스의 값이 보다 이전 이거나 이후 이면이 MinSupportedDateTime MaxSupportedDateTime 메서드는을 throw ArgumentOutOfRangeException 합니다.If the value of the current DateTime instance is earlier than MinSupportedDateTime or later than MaxSupportedDateTime, the method throws an ArgumentOutOfRangeException. 다음 예제에서 이에 대해 설명합니다.The following example provides an illustration. HijriCalendar현재 문화권이 아랍어 (시리아) 일 때 클래스의 범위를 벗어나는 날짜의 형식을 지정 하려고 합니다.It attempts to format a date that is outside the range of the HijriCalendar class when the current culture is Arabic (Syria).
::: code language = "csharp" source = "~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception2.cs" id = "Snippet2":::::: code language = "vb" source = "~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception2.vb" id = "Snippet2"::::::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception2.cs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception2.vb" id="Snippet2":::