Share via


Date and Time Format Strings

Date and time format strings control formatting operations in which a date and/or time is represented as a string. The date and time value can be represented by either a DateTime or a DateTimeOffset value.

Date and time format strings fall into two categories:

  • Standard DateTime format strings.

    Standard date and time format strings consist of one standard date and time format specifier. Each standard format specifier denotes a particular, commonly used string representation of a date and time.

  • Custom DateTime format strings.

    Custom date and time format strings consist of one or more custom numeric format specifiers. Combine custom date and time format specifiers to define an application-specific pattern that determines how date and time data is formatted

Date and time format strings are supported by the ToString method of the DateTime and DateTimeOffset types. Date and time format strings are also supported by the .NET Framework composite formatting feature, which is used by certain Write and WriteLine methods of the Console and StreamWriter classes, the String.Format method, and the StringBuilder.AppendFormat method.

See Also

Concepts

Formatting Overview

Standard Date and Time Format Strings

Custom Date and Time Format Strings

Other Resources

Formatting Types