Skip to main content
Version: 3.0.10 (latest)

Produce spoken dates and clock times

Orientation

Use date ordinal words when a calendar date should read naturally, and clock notation when a TimeOnly value should become a phrase such as “twenty-five past one.” These are localized presentation operations, distinct from relative time and numeric ordinal suffixes.

Example

Neither API accepts a culture parameter, so this executable scopes both ambient cultures before making the calls:

Program.cs
using System.Globalization;
using Humanizer;

var culture = CultureInfo.GetCultureInfo("en-US");
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;

var date = new DateTime(2022, 1, 25).ToOrdinalWords();
var time = new TimeOnly(13, 23)
.ToClockNotation(ClockNotationRounding.NearestFiveMinutes);

AssertEqual("January 25th, 2022", date);
AssertEqual("twenty-five past one", time);

Console.WriteLine($"{date}; {time}");

static void AssertEqual(string expected, string actual)
{
if (actual != expected)
throw new InvalidOperationException($"Expected '{expected}', got '{actual}'.");
}

Date ordinal words

DateTime.ToOrdinalWords() and DateOnly.ToOrdinalWords() order the day, month, and year for the current UI culture. A GrammaticalCase overload is available for locales whose date converter supports case-sensitive wording.

Clock notation

TimeOnly.ToClockNotation() renders the exact minute. ClockNotationRounding.NearestFiveMinutes first rounds to the nearest five-minute boundary, then selects the phrase. Rounding can cross an hour or day-period boundary.

Pitfall

Locale capability is not uniform. A successful number-word conversion does not prove that the same locale supplies date ordinal words, grammatical cases, or clock notation. Check supported cultures and capabilities and set ambient culture at the request or job boundary.

Version notes

DateTime.ToOrdinalWords predates the documented corpus. DateOnly date words begin with its framework support in 2.11.10. Clock notation appears in 2.13.14; this page and executable must be excluded from earlier snapshots.