From 97c2bd98532691618cfce245fc40eb1283610559 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 25 Jul 2025 23:09:21 +0000 Subject: [PATCH 1/3] Initial plan From 635bae6fe1831badc0824f5785dedcee1664e014 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 25 Jul 2025 23:22:22 +0000 Subject: [PATCH 2/3] Update standard date and time format strings documentation to include DateOnly and TimeOnly Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com> --- .../standard-date-and-time-format-strings.md | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/standard/base-types/standard-date-and-time-format-strings.md b/docs/standard/base-types/standard-date-and-time-format-strings.md index d4dd732a0ebeb..6d222b6d85c2d 100644 --- a/docs/standard/base-types/standard-date-and-time-format-strings.md +++ b/docs/standard/base-types/standard-date-and-time-format-strings.md @@ -17,11 +17,11 @@ ms.topic: reference --- # Standard date and time format strings -A standard date and time format string uses a single character as the format specifier to define the text representation of a or a value. Any date and time format string that contains more than one character, including white space, is interpreted as a [custom date and time format string](custom-date-and-time-format-strings.md). A standard or custom format string can be used in two ways: +A standard date and time format string uses a single character as the format specifier to define the text representation of a , , , or value. Any date and time format string that contains more than one character, including white space, is interpreted as a [custom date and time format string](custom-date-and-time-format-strings.md). A standard or custom format string can be used in two ways: - To define the string that results from a formatting operation. -- To define the text representation of a date and time value that can be converted to a or value by a parsing operation. +- To define the text representation of a date and time value that can be converted to a , , , or value by a parsing operation. > [!TIP] > You can download the **Formatting Utility**, a .NET Windows Forms application that lets you apply format strings to either numeric or date and time values and display the result string. Source code is available for [C#](/samples/dotnet/samples/windowsforms-formatting-utility-cs) and [Visual Basic](/samples/dotnet/samples/windowsforms-formatting-utility-vb). @@ -30,22 +30,22 @@ A standard date and time format string uses a single character as the format spe ## Table of format specifiers - The following table describes the standard date and time format specifiers. Unless otherwise noted, a particular standard date and time format specifier produces an identical string representation regardless of whether it is used with a or a value. See [Control Panel Settings](#control-panel-settings) and [DateTimeFormatInfo Properties](#datetimeformatinfo-properties) for additional information about using standard date and time format strings. + The following table describes the standard date and time format specifiers. Unless otherwise noted, a particular standard date and time format specifier produces an identical string representation regardless of whether it is used with a or a value. See [Notes](#notes) for additional information about using standard date and time format strings with and values. See [Control Panel Settings](#control-panel-settings) and [DateTimeFormatInfo Properties](#datetimeformatinfo-properties) for additional information about using standard date and time format strings. |Format specifier|Description|Examples| |----------------------|-----------------|--------------| -|"d"|Short date pattern.

More information:[The short date ("d") format specifier](#ShortDate).|2009-06-15T13:45:30 -> 6/15/2009 (en-US)

2009-06-15T13:45:30 -> 15/06/2009 (fr-FR)

2009-06-15T13:45:30 -> 2009/06/15 (ja-JP)| +|"d"|Short date pattern.

More information:[The short date ("d") format specifier](#ShortDate).|2009-06-15T13:45:30 -> 6/15/2009 (en-US)

2009-06-15T13:45:30 -> 15/06/2009 (fr-FR)

2009-06-15T13:45:30 -> 2009/06/15 (ja-JP)

(2009-06-15) -> 6/15/2009 (en-US)| |"D"|Long date pattern.

More information:[The long date ("D") format specifier](#LongDate).|2009-06-15T13:45:30 -> Monday, June 15, 2009 (en-US)

2009-06-15T13:45:30 -> понедельник, 15 июня 2009 г. (ru-RU)

2009-06-15T13:45:30 -> Montag, 15. Juni 2009 (de-DE)| |"f"|Full date/time pattern (short time).

More information: [The full date short time ("f") format specifier](#FullDateShortTime).|2009-06-15T13:45:30 -> Monday, June 15, 2009 1:45 PM (en-US)

2009-06-15T13:45:30 -> den 15 juni 2009 13:45 (sv-SE)

2009-06-15T13:45:30 -> Δευτέρα, 15 Ιουνίου 2009 1:45 μμ (el-GR)| |"F"|Full date/time pattern (long time).

More information: [The full date long time ("F") format specifier](#FullDateLongTime).|2009-06-15T13:45:30 -> Monday, June 15, 2009 1:45:30 PM (en-US)

2009-06-15T13:45:30 -> den 15 juni 2009 13:45:30 (sv-SE)

2009-06-15T13:45:30 -> Δευτέρα, 15 Ιουνίου 2009 1:45:30 μμ (el-GR)| |"g"|General date/time pattern (short time).

More information: [The general date short time ("g") format specifier](#GeneralDateShortTime).|2009-06-15T13:45:30 -> 6/15/2009 1:45 PM (en-US)

2009-06-15T13:45:30 -> 15/06/2009 13:45 (es-ES)

2009-06-15T13:45:30 -> 2009/6/15 13:45 (zh-CN)| |"G"|General date/time pattern (long time).

More information: [The general date long time ("G") format specifier](#GeneralDateLongTime).|2009-06-15T13:45:30 -> 6/15/2009 1:45:30 PM (en-US)

2009-06-15T13:45:30 -> 15/06/2009 13:45:30 (es-ES)

2009-06-15T13:45:30 -> 2009/6/15 13:45:30 (zh-CN)| |"M", "m"|Month/day pattern.

More information: [The month ("M", "m") format specifier](#MonthDay).|2009-06-15T13:45:30 -> June 15 (en-US)

2009-06-15T13:45:30 -> 15. juni (da-DK)

2009-06-15T13:45:30 -> 15 Juni (id-ID)| -|"O", "o"|round-trip date/time pattern.

More information: [The round-trip ("O", "o") format specifier](#Roundtrip).| values:

2009-06-15T13:45:30 (DateTimeKind.Local) --> 2009-06-15T13:45:30.0000000-07:00

2009-06-15T13:45:30 (DateTimeKind.Utc) --> 2009-06-15T13:45:30.0000000Z

2009-06-15T13:45:30 (DateTimeKind.Unspecified) --> 2009-06-15T13:45:30.0000000

values:

2009-06-15T13:45:30-07:00 --> 2009-06-15T13:45:30.0000000-07:00| +|"O", "o"|round-trip date/time pattern.

More information: [The round-trip ("O", "o") format specifier](#Roundtrip).| values:

2009-06-15T13:45:30 (DateTimeKind.Local) --> 2009-06-15T13:45:30.0000000-07:00

2009-06-15T13:45:30 (DateTimeKind.Utc) --> 2009-06-15T13:45:30.0000000Z

2009-06-15T13:45:30 (DateTimeKind.Unspecified) --> 2009-06-15T13:45:30.0000000

values:

2009-06-15T13:45:30-07:00 --> 2009-06-15T13:45:30.0000000-07:00

values:

2009-06-15 --> 2009-06-15

values:

13:45:30 --> 13:45:30.0000000| |"R", "r"|RFC1123 pattern.

More information: [The RFC1123 ("R", "r") format specifier](#RFC1123).| input: 2009-06-15T13:45:30 -> Mon, 15 Jun 2009 20:45:30 GMT
input: 2009-06-15T13:45:30 -> Mon, 15 Jun 2009 13:45:30 GMT | |"s"|Sortable date/time pattern.

More information: [The sortable ("s") format specifier](#Sortable).|2009-06-15T13:45:30 (DateTimeKind.Local) -> 2009-06-15T13:45:30

2009-06-15T13:45:30 (DateTimeKind.Utc) -> 2009-06-15T13:45:30| -|"t"|Short time pattern.

More information: [The short time ("t") format specifier](#ShortTime).|2009-06-15T13:45:30 -> 1:45 PM (en-US)

2009-06-15T13:45:30 -> 13:45 (hr-HR)

2009-06-15T13:45:30 -> 01:45 م (ar-EG)| -|"T"|Long time pattern.

More information: [The long time ("T") format specifier](#LongTime).|2009-06-15T13:45:30 -> 1:45:30 PM (en-US)

2009-06-15T13:45:30 -> 13:45:30 (hr-HR)

2009-06-15T13:45:30 -> 01:45:30 م (ar-EG)| +|"t"|Short time pattern.

More information: [The short time ("t") format specifier](#ShortTime).|2009-06-15T13:45:30 -> 1:45 PM (en-US)

2009-06-15T13:45:30 -> 13:45 (hr-HR)

2009-06-15T13:45:30 -> 01:45 م (ar-EG)

(13:45:30) -> 1:45 PM (en-US)| +|"T"|Long time pattern.

More information: [The long time ("T") format specifier](#LongTime).|2009-06-15T13:45:30 -> 1:45:30 PM (en-US)

2009-06-15T13:45:30 -> 13:45:30 (hr-HR)

2009-06-15T13:45:30 -> 01:45:30 م (ar-EG)

(13:45:30) -> 1:45:30 PM (en-US)| |"u"|Universal sortable date/time pattern.

More information: [The universal sortable ("u") format specifier](#UniversalSortable).|With a value: 2009-06-15T13:45:30 -> 2009-06-15 13:45:30Z

With a value: 2009-06-15T13:45:30 -> 2009-06-15 20:45:30Z| |"U"|Universal full date/time pattern.

More information: [The universal full ("U") format specifier](#UniversalFull).|2009-06-15T13:45:30 -> Monday, June 15, 2009 8:45:30 PM (en-US)

2009-06-15T13:45:30 -> den 15 juni 2009 20:45:30 (sv-SE)

2009-06-15T13:45:30 -> Δευτέρα, 15 Ιουνίου 2009 8:45:30 μμ (el-GR)| |"Y", "y"|Year month pattern.

More information: [The year month ("Y") format specifier](#YearMonth).|2009-06-15T13:45:30 -> June 2009 (en-US)

2009-06-15T13:45:30 -> juni 2009 (da-DK)

2009-06-15T13:45:30 -> Juni 2009 (id-ID)| @@ -84,12 +84,12 @@ In some cases, the standard format string serves as a convenient abbreviation fo |"s"||yyyy'-'MM'-'dd'T'HH':'mm':'ss| |"u"||yyyy'-'MM'-'dd HH':'mm':'ss'Z'| -Standard format strings can also be used in parsing operations with the or methods, which require an input string to exactly conform to a particular pattern for the parse operation to succeed. Many standard format strings map to multiple custom format strings, so a date and time value can be represented in a variety of formats and the parse operation will still succeed. You can determine the custom format string or strings that correspond to a standard format string by calling the method. The following example displays the custom format strings that map to the "d" (short date pattern) standard format string. +Standard format strings can also be used in parsing operations with the , , , or methods, which require an input string to exactly conform to a particular pattern for the parse operation to succeed. Many standard format strings map to multiple custom format strings, so a date and time value can be represented in a variety of formats and the parse operation will still succeed. You can determine the custom format string or strings that correspond to a standard format string by calling the method. The following example displays the custom format strings that map to the "d" (short date pattern) standard format string. [!code-csharp[Formatting.DateAndTime.Standard#17](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.DateAndTime.Standard/cs/stdandparsing1.cs#17)] [!code-vb[Formatting.DateAndTime.Standard#17](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.DateAndTime.Standard/vb/stdandparsing1.vb#17)] -The following sections describe the standard format specifiers for and values. +The following sections describe the standard format specifiers for , , , and values. ## Date formats @@ -256,6 +256,8 @@ The following example uses the "G" format specifier to display a date and time v The "O" or "o" standard format specifier represents a custom date and time format string using a pattern that preserves time zone information and emits a result string that complies with ISO 8601. For values, this format specifier is designed to preserve date and time values along with the property in text. The formatted string can be parsed back by using the or method if the `styles` parameter is set to . +For values, this format specifier produces a date-only ISO 8601 string in the format "yyyy-MM-dd". For values, it produces a time-only ISO 8601 string in the format "HH:mm:ss.fffffff". + The "O" or "o" standard format specifier corresponds to the "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK" custom format string for values and to the "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffzzz" custom format string for values. In this string, the pairs of single quotation marks that delimit individual characters, such as the hyphens, the colons, and the letter "T", indicate that the individual character is a literal that cannot be changed. The apostrophes do not appear in the output string. The "O" or "o" standard format specifier (and the "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK" custom format string) takes advantage of the three ways that ISO 8601 represents time zone information to preserve the property of values: @@ -268,7 +270,7 @@ The "O" or "o" standard format specifier (and the "yyyy'-'MM'-'dd'T'HH':'mm':'ss Because the "O" or "o" standard format specifier conforms to an international standard, the formatting or parsing operation that uses the specifier always uses the invariant culture and the Gregorian calendar. -Strings that are passed to the `Parse`, `TryParse`, `ParseExact`, and `TryParseExact` methods of and can be parsed by using the "O" or "o" format specifier if they are in one of these formats. In the case of objects, the parsing overload that you call should also include a `styles` parameter with a value of . Note that if you call a parsing method with the custom format string that corresponds to the "O" or "o" format specifier, you won't get the same results as "O" or "o". This is because parsing methods that use a custom format string can't parse the string representation of date and time values that lack a time zone component or use "Z" to indicate UTC. +Strings that are passed to the `Parse`, `TryParse`, `ParseExact`, and `TryParseExact` methods of , , , and can be parsed by using the "O" or "o" format specifier if they are in one of these formats. In the case of objects, the parsing overload that you call should also include a `styles` parameter with a value of . Note that if you call a parsing method with the custom format string that corresponds to the "O" or "o" format specifier, you won't get the same results as "O" or "o". This is because parsing methods that use a custom format string can't parse the string representation of date and time values that lack a time zone component or use "Z" to indicate UTC. The following example uses the "o" format specifier to display a series of values and a value on a system in the U.S. Pacific Time zone. @@ -463,6 +465,26 @@ The following example uses the "y" format specifier to display a date and time v +## Notes + +### DateOnly and TimeOnly formatting + + and types support a subset of the standard date and time format strings: + +- **** supports date-related format specifiers: + - "d" (short date), "D" (long date) + - "M" or "m" (month/day) + - "Y" or "y" (year/month) + - "O" or "o" (round-trip, date portion only) + - "R" or "r" (RFC1123, date portion only) + +- **** supports time-related format specifiers: + - "t" (short time), "T" (long time) + - "O" or "o" (round-trip, time portion only) + - "R" or "r" (RFC1123, time portion only) + +Format specifiers that combine both date and time information (such as "f", "F", "g", "G", "s", "u", "U") throw a when used with or . + ## Control Panel settings In Windows, the settings in the **Regional and Language Options** item in Control Panel influence the result string produced by a formatting operation. These settings are used to initialize the object associated with the current culture, which provides values used to govern formatting. Computers that use different settings generate different result strings. From 8f369f6d5d1ca8ec3841c88b6008e3022bb07a57 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Sat, 26 Jul 2025 20:09:46 -0700 Subject: [PATCH 3/3] Apply suggestions from code review --- .../base-types/standard-date-and-time-format-strings.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/standard/base-types/standard-date-and-time-format-strings.md b/docs/standard/base-types/standard-date-and-time-format-strings.md index 6d222b6d85c2d..b5bd0d22c9c42 100644 --- a/docs/standard/base-types/standard-date-and-time-format-strings.md +++ b/docs/standard/base-types/standard-date-and-time-format-strings.md @@ -30,7 +30,7 @@ A standard date and time format string uses a single character as the format spe ## Table of format specifiers - The following table describes the standard date and time format specifiers. Unless otherwise noted, a particular standard date and time format specifier produces an identical string representation regardless of whether it is used with a or a value. See [Notes](#notes) for additional information about using standard date and time format strings with and values. See [Control Panel Settings](#control-panel-settings) and [DateTimeFormatInfo Properties](#datetimeformatinfo-properties) for additional information about using standard date and time format strings. + The following table describes the standard date and time format specifiers. Unless otherwise noted, a particular standard date and time format specifier produces an identical string representation regardless of whether it is used with a or a value. Not all format specifiers can be used with and values; for additional information, see [DateOnly and TimeOnly formatting](#dateonly-and-timeonly-formatting). For information about how regional settings on Windows and the current object can affect date and time formatting, see [Control Panel Settings](#control-panel-settings) and [DateTimeFormatInfo Properties](#datetimeformatinfo-properties). |Format specifier|Description|Examples| |----------------------|-----------------|--------------| @@ -84,7 +84,7 @@ In some cases, the standard format string serves as a convenient abbreviation fo |"s"||yyyy'-'MM'-'dd'T'HH':'mm':'ss| |"u"||yyyy'-'MM'-'dd HH':'mm':'ss'Z'| -Standard format strings can also be used in parsing operations with the , , , or methods, which require an input string to exactly conform to a particular pattern for the parse operation to succeed. Many standard format strings map to multiple custom format strings, so a date and time value can be represented in a variety of formats and the parse operation will still succeed. You can determine the custom format string or strings that correspond to a standard format string by calling the method. The following example displays the custom format strings that map to the "d" (short date pattern) standard format string. +Standard format strings can also be used in parsing operations with the , , , and methods, which require an input string to exactly conform to a particular pattern for the parse operation to succeed. Many standard format strings map to multiple custom format strings, so a date and time value can be represented in a variety of formats and the parse operation will still succeed. You can determine the custom format string or strings that correspond to a standard format string by calling the method. The following example displays the custom format strings that map to the "d" (short date pattern) standard format string. [!code-csharp[Formatting.DateAndTime.Standard#17](../../../samples/snippets/csharp/VS_Snippets_CLR/Formatting.DateAndTime.Standard/cs/stdandparsing1.cs#17)] [!code-vb[Formatting.DateAndTime.Standard#17](../../../samples/snippets/visualbasic/VS_Snippets_CLR/Formatting.DateAndTime.Standard/vb/stdandparsing1.vb#17)] @@ -465,9 +465,7 @@ The following example uses the "y" format specifier to display a date and time v -## Notes - -### DateOnly and TimeOnly formatting +## DateOnly and TimeOnly formatting and types support a subset of the standard date and time format strings: