Skip to content

Update standard date and time format strings documentation to include DateOnly and TimeOnly #47591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 25, 2025

The "Standard date and time format strings" documentation page previously only covered DateTime and DateTimeOffset types, but did not include the DateOnly and TimeOnly types that were introduced in .NET 6. This update adds comprehensive coverage for these new types.

Changes Made

  • Updated introduction: Added DateOnly and TimeOnly to the main description alongside DateTime and DateTimeOffset
  • Added Notes section: New dedicated section explaining which format specifiers work with each type
  • Updated format specifier table: Added examples showing DateOnly and TimeOnly usage for supported formats
  • Enhanced parsing documentation: Added references to DateOnly.ParseExact and TimeOnly.ParseExact methods
  • Updated round-trip format section: Explained how the "O"/"o" format specifier works with the new types

Format Specifier Compatibility

The documentation now clearly explains that:

  • DateOnly supports date-related format specifiers: "d", "D", "M"/"m", "Y"/"y", "O"/"o", "R"/"r"
  • TimeOnly supports time-related format specifiers: "t", "T", "O"/"o", "R"/"r"
  • Both types throw FormatException for combined date/time formats: "f", "F", "g", "G", "s", "u", "U"

Examples Added

// DateOnly formatting
var date = new DateOnly(2009, 6, 15);
Console.WriteLine(date.ToString("d")); // 6/15/2009 (en-US)
Console.WriteLine(date.ToString("O")); // 2009-06-15

// TimeOnly formatting  
var time = new TimeOnly(13, 45, 30);
Console.WriteLine(time.ToString("T")); // 1:45:30 PM (en-US)
Console.WriteLine(time.ToString("O")); // 13:45:30.0000000

This ensures developers have complete documentation for all four .NET date/time types in one comprehensive reference.

Fixes #43423.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/standard/base-types/standard-date-and-time-format-strings.md Standard date and time format strings

… DateOnly and TimeOnly

Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Update "Standard date and time format strings" page to include DateOnly and TimeOnly Update standard date and time format strings documentation to include DateOnly and TimeOnly Jul 25, 2025
@Copilot Copilot AI requested a review from gewarren July 25, 2025 23:25
Copilot finished work on behalf of gewarren July 25, 2025 23:25
@gewarren gewarren marked this pull request as ready for review July 27, 2025 03:10
@gewarren gewarren requested review from adegeo and a team as code owners July 27, 2025 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update "Standard date and time format strings" page to include DateOnly and TimeOnly
2 participants