class in Unity.SmartStrings.Extensions
/
Inherits from:Unity.SmartStrings.Core.Extensions.FormatterBase
Formats time spans as human-readable text, such as 1 day 2 hours.
Call the formatter by name, as in {0:time:}. It accepts TimeSpan, DateTime
and DateTimeOffset values. For a DateTime or DateTimeOffset, it shows
the time between that value and now. Words in the format text, such as short or noless, set
TimeSpanFormatOptions for that placeholder. Without a nested format, the formatter joins the unit
texts with spaces. When the format holds a nested placeholder, the formatter passes the list of unit texts to it
instead, so a nested list format can choose the separators, as in {0:time:abbr {:list:|, | and }}. Only
the words before the nested placeholder set options.
Additional resources: TimeSpanFormatOptions, ListFormatter
using System; using System.Globalization; using Unity.SmartStrings; using Unity.SmartStrings.Extensions; using UnityEngine;
public static class TimeFormatterExample { public static void FormatDuration() { var smart = Smart.CreateDefaultSmartFormat(); smart.AddExtensions(new TimeFormatter());
var english = CultureInfo.GetCultureInfo("en"); var duration = new TimeSpan(1, 1, 1, 1);
Debug.Log(smart.Format(english, "{0:time:}", duration)); // 1 day 1 hour 1 minute 1 second Debug.Log(smart.Format(english, "{0:time: {:list:|, | and }}", duration)); // 1 day, 1 hour, 1 minute and 1 second } }
| Property | Description |
|---|---|
| DefaultFormatOptions | The options that control how time values are formatted. |
| FallbackLanguage | The fallback language used when no supported language is found. Default is "en". If no fallback language shall be used, set it to String.Empty. |
| Constructor | Description |
|---|---|
| TimeFormatter | Initializes the extension with a default Unity.SmartStrings.Extensions.Time.Utilities.TimeTextInfo. |
| Property | Description |
|---|---|
| DefaultName | Default name to use when FormatterBase.Name is null. |