TimeTagHelper Class

Converts a DateTimeOffset value to a properly formatted datetime attribute for HTML elements.

public sealed class TimeTagHelper : TagHelper

Remarks

The value is normalized to UTC and always written with the Z designator. A datetime attribute without a time zone designator is interpreted as local time by the reader, which would shift the value by the reader's UTC offset.

Example

<time datetime-value="@DateTimeOffset.UtcNow">Just now</time>
@* Rendered as <time datetime="2024-01-15T10:30:45.123Z">Just now</time> *@
Inheritance
TagHelper TimeTagHelper

Constructors

NameDescription
TimeTagHelper()

TimeTagHelper()

public TimeTagHelper()

No documentation is available.

Properties

NameDescription
DatetimeGets or sets the date and time to format for the datetime attribute.

Gets or sets the date and time to format for the datetime attribute.

public DateTimeOffset? Datetime { get; set; }

Property value

DateTimeOffset?

Methods

NameDescription
Process(TagHelperContext, TagHelperOutput)Processes the tag helper and sets the datetime attribute in ISO 8601 format.

Process(TagHelperContext, TagHelperOutput)

TimeTagHelper.cs

Processes the tag helper and sets the datetime attribute in ISO 8601 format.

public override void Process(TagHelperContext context, TagHelperOutput output)

Parameters

context TagHelperContext
output TagHelperOutput