Skip to content

Commit

Permalink
List all standard format strings in the menu
Browse files Browse the repository at this point in the history
Standard strings are better because they conform to the user's locale.
  • Loading branch information
danielchalmers committed Jul 16, 2024
1 parent 1e5c9e3 commit 08c2ba5
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions DesktopClock/DateFormatExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,40 @@ private DateFormatExample(string format, string example)
/// <summary>
/// Common date time formatting strings and an example string for each.
/// </summary>
/// <remarks>https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings</remarks>
/// <remarks>
/// <see href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings">Standard date and time format strings</see>
/// <br/>
/// <see href="https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings">Custom date and time format strings</see>
/// </remarks>
public static IReadOnlyCollection<DateFormatExample> DefaultExamples { get; } = new[]
{
"M",
"dddd, MMMM dd",
"dddd, MMMM dd, HH:mm",
"dddd, MMMM dd, h:mm tt",
"dddd, MMM dd, HH:mm",
"dddd, MMM dd, h:mm tt",
"dddd, MMM dd, HH:mm:ss",
"dddd, MMM dd, h:mm:ss tt",
"ddd, MMM dd, HH:mm",
"ddd, MMM dd, h:mm tt",
"ddd, MMM dd, HH:mm:ss",
"ddd, MMM dd, h:mm:ss tt",
"ddd, MMM dd, HH:mm K",
"ddd, MMM dd, h:mm tt K",
"d",
"g",
"G",
"t",
"T",
"O",
"dddd, MMMM dd", // Custom format: "Monday, April 10"
"dddd, MMMM dd, HH:mm", // Custom format: "Monday, April 10, 14:30"
"dddd, MMMM dd, h:mm tt", // Custom format: "Monday, April 10, 2:30 PM"
"dddd, MMM dd, HH:mm", // Custom format: "Monday, Apr 10, 14:30"
"dddd, MMM dd, h:mm tt", // Custom format: "Monday, Apr 10, 2:30 PM"
"dddd, MMM dd, HH:mm:ss", // Custom format: "Monday, Apr 10, 14:30:45"
"dddd, MMM dd, h:mm:ss tt", // Custom format: "Monday, Apr 10, 2:30:45 PM"
"ddd, MMM dd, HH:mm", // Custom format: "Mon, Apr 10, 14:30"
"ddd, MMM dd, h:mm tt", // Custom format: "Mon, Apr 10, 2:30 PM"
"ddd, MMM dd, HH:mm:ss", // Custom format: "Mon, Apr 10, 14:30:45"
"ddd, MMM dd, h:mm:ss tt", // Custom format: "Mon, Apr 10, 2:30:45 PM"
"ddd, MMM dd, HH:mm K", // Custom format: "Mon, Apr 10, 14:30 +02:00"
"ddd, MMM dd, h:mm tt K", // Custom format: "Mon, Apr 10, 2:30 PM +02:00"
"d", // Short date pattern: 6/15/2009 (en-US)
"D", // Long date pattern: Monday, June 15, 2009 (en-US)
"f", // Full date/time pattern (short time): Monday, June 15, 2009 1:45 PM (en-US)
"F", // Full date/time pattern (long time): Monday, June 15, 2009 1:45:30 PM (en-US)
"g", // General date/time pattern (short time): 6/15/2009 1:45 PM (en-US)
"G", // General date/time pattern (long time): 6/15/2009 1:45:30 PM (en-US)
"M", // Month/day pattern: June 15 (en-US)
"O", // Round-trip date/time pattern: 2009-06-15T13:45:30.0000000-07:00 (DateTimeOffset)
"R", // RFC1123 pattern: Mon, 15 Jun 2009 20:45:30 GMT (DateTimeOffset)
"s", // Sortable date/time pattern: 2009-06-15T13:45:30
"t", // Short time pattern: 1:45 PM (en-US)
"T", // Long time pattern: 1:45:30 PM (en-US)
"u", // Universal sortable date/time pattern: 2009-06-15 13:45:30Z (DateTime)
//"U", // Universal full date/time pattern: Monday, June 15, 2009 8:45:30 PM (en-US) // Not available for DateTimeOffset.
"Y", // Year month pattern: June 2009 (en-US)
}.Select(f => FromFormat(f, DateTimeOffset.Now)).Append(Tutorial).ToList();
}
}

0 comments on commit 08c2ba5

Please sign in to comment.