Click or drag to resize
DateTimeToString Method (String, IFormatProvider)
Converts the value of the current DateTime object to its equivalent string representation using the specified format and culture-specific format information.

Namespace: System
Assembly: mscorlib (in mscorlib.dll) Version: 4.0.0.0
Syntax
C#
public string ToString(
	string format,
	IFormatProvider provider
)

Parameters

format
Type: SystemString
A standard or custom date and time format string.
provider
Type: SystemIFormatProvider
An object that supplies culture-specific formatting information.

Return Value

Type: String
A string representation of value of the current DateTime object as specified by format and provider.
Exceptions
ExceptionCondition
FormatExceptionThe length of format is 1, and it is not one of the format specifier characters defined for DateTimeFormatInfo.-or- format does not contain a valid custom format pattern.
ArgumentOutOfRangeExceptionThe date and time is outside the range of dates supported by the calendar used by provider.
See Also