Skip to main content
Version: 2.10.1

Date, time, duration, and age scenarios

Orientation​

Choose the guide by the meaning of the value and the sentence you need:

TaskFocused guide
Produce “yesterday” or “3 hours ago”Relative dates and times
Produce “2 hours, 5 minutes” or an age phraseDurations and ages
Build a readable TimeSpan or DateTimeFluent dates and time spans

Example​

This verified source demonstrates the two most common display boundaries: a relative UTC date with an injected comparison instant and a two-unit elapsed duration:

Program.cs
using System.Globalization;
using Humanizer;

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

var comparison = new DateTime(2025, 1, 20, 12, 0, 0, DateTimeKind.Utc);
var relative = comparison.AddDays(-1).Humanize(
utcDate: true,
dateToCompareAgainst: comparison,
culture: culture);
var duration = TimeSpan.FromMinutes(125).Humanize(precision: 2, culture: culture);

AssertEqual("yesterday", relative);
AssertEqual("2 hours, 5 minutes", duration);

Console.WriteLine($"{relative}; {duration}");

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

It prints yesterday; 2 hours, 5 minutes. Follow the focused guides for the full overload contracts.

Pick a model before an API​

  • Use DateTimeOffset when an instant and offset matter.
  • Use TimeSpan for elapsed duration, not calendar arithmetic.

Pitfall​

Reading Now inside formatting makes examples, tests, and cache behavior unstable. Inject comparison values and set culture explicitly. A TimeSpan has no calendar context, so months, years, and ages are approximations; use date arithmetic when leap years, month length, or birthdays must be exact.

Version notes​

DateTime, DateTimeOffset, and TimeSpan are available in this 2.x release. DateOnly, TimeOnly, clock notation, and ToAge are unavailable.