Humanizer.TimeOnlyToClockNotationExtensions
TimeOnlyToClockNotationExtensions Class
Humanizes TimeOnly into human readable sentence
public static class TimeOnlyToClockNotationExtensions
Inheritance System.Object → TimeOnlyToClockNotationExtensions
Methods
TimeOnlyToClockNotationExtensions.ToClockNotation(this TimeOnly, ClockNotationRounding) Method
Converts a System.TimeOnly value to its clock notation string representation (e.g., "three o'clock", "half past four", "quarter to six").
public static string ToClockNotation(this System.TimeOnly input, Humanizer.ClockNotationRounding roundToNearestFive=Humanizer.ClockNotationRounding.None);
Parameters
input System.TimeOnly
The time to be converted to clock notation.
roundToNearestFive ClockNotationRounding
Specifies whether and how to round the minutes. Default is None. - None: Use exact minutes - NearestFiveMinutes: Round to nearest 5 minutes
Returns
System.String
A culture-specific string representation of the time in clock notation.
For English: "three o'clock", "ten past four", "quarter to six", etc.
Example
// English (en-US) examples:
new TimeOnly(15, 0).ToClockNotation() => "three o'clock"
new TimeOnly(15, 15).ToClockNotation() => "quarter past three"
new TimeOnly(15, 30).ToClockNotation() => "half past three"
new TimeOnly(15, 45).ToClockNotation() => "quarter to four"
new TimeOnly(15, 7).ToClockNotation(ClockNotationRounding.NearestFiveMinutes) => "five past three"
Remarks
The output format varies by culture. Some cultures express time differently than others. This method is only available on .NET 6.0 and later.