Skip to main content
Version: 3.0.8

Humanizer.TimeSpanHumanizeExtensions

TimeSpanHumanizeExtensions Class

Humanizes TimeSpan into human readable form

public static class TimeSpanHumanizeExtensions

Inheritance System.Object → TimeSpanHumanizeExtensions

Methods

TimeSpanHumanizeExtensions.Humanize(this TimeSpan, int, bool, CultureInfo, TimeUnit, TimeUnit, string, bool) Method

Turns a TimeSpan into a human readable form. E.g. 1 day.

public static string Humanize(this System.TimeSpan timeSpan, int precision, bool countEmptyUnits, System.Globalization.CultureInfo? culture=null, Humanizer.TimeUnit maxUnit=Humanizer.TimeUnit.Week, Humanizer.TimeUnit minUnit=Humanizer.TimeUnit.Millisecond, string? collectionSeparator=", ", bool toWords=false);

Parameters

timeSpan System.TimeSpan

precision System.Int32

The maximum number of time units to return.

countEmptyUnits System.Boolean

Controls whether empty time units should be counted towards maximum number of time units. Leading empty time units never count.

culture System.Globalization.CultureInfo

Culture to use. If null, current thread's UI culture is used.

maxUnit TimeUnit

The maximum unit of time to output. The default value is Week. The time units Month and Year will give approximations for time spans bigger than 30 days by calculating with 365.2425 days a year and 30.4369 days a month.

minUnit TimeUnit

The minimum unit of time to output.

collectionSeparator System.String

The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used.

toWords System.Boolean

Uses words instead of numbers if true. E.g. one day.

Returns

System.String

TimeSpanHumanizeExtensions.Humanize(this TimeSpan, int, CultureInfo, TimeUnit, TimeUnit, string, bool) Method

Turns a TimeSpan into a human readable form. E.g. 1 day.

public static string Humanize(this System.TimeSpan timeSpan, int precision=1, System.Globalization.CultureInfo? culture=null, Humanizer.TimeUnit maxUnit=Humanizer.TimeUnit.Week, Humanizer.TimeUnit minUnit=Humanizer.TimeUnit.Millisecond, string? collectionSeparator=", ", bool toWords=false);

Parameters

timeSpan System.TimeSpan

precision System.Int32

The maximum number of time units to return. Defaulted is 1 which means the largest unit is returned

culture System.Globalization.CultureInfo

Culture to use. If null, current thread's UI culture is used.

maxUnit TimeUnit

The maximum unit of time to output. The default value is Week. The time units Month and Year will give approximations for time spans bigger 30 days by calculating with 365.2425 days a year and 30.4369 days a month.

minUnit TimeUnit

The minimum unit of time to output.

collectionSeparator System.String

The separator to use when combining humanized time parts. If null, the default collection formatter for the current culture is used.

toWords System.Boolean

Uses words instead of numbers if true. E.g. one day.

Returns

System.String

TimeSpanHumanizeExtensions.ToAge(this TimeSpan, CultureInfo, TimeUnit, bool) Method

Turns a TimeSpan into an age expression, e.g. "40 years old"

public static string ToAge(this System.TimeSpan timeSpan, System.Globalization.CultureInfo? culture=null, Humanizer.TimeUnit maxUnit=Humanizer.TimeUnit.Year, bool toWords=false);

Parameters

timeSpan System.TimeSpan

Elapsed time

culture System.Globalization.CultureInfo

Culture to use. If null, current thread's UI culture is used.

maxUnit TimeUnit

The maximum unit of time to output. The default value is Year.

toWords System.Boolean

Uses words instead of numbers if true. E.g. "forty years old".

Returns

System.String
Age expression in the given culture/language