Timestamp
Importing
Add rh-timestamp to your page with this import statement:
<script type="module">
import '@rhds/elements/rh-timestamp/rh-timestamp.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
To learn more about installing RHDS elements on your site using an import map read our getting started docs.
Usage
<rh-timestamp date="Tue Aug 09 2006 14:57:00 GMT-0400"></rh-timestamp>
<script type="module">
import '@rhds/elements/rh-timestamp/rh-timestamp.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
rh-timestamp
Provides locale-aware date and time formatting for consistent display
across pages. Renders a <time> element with an ARIA-accessible
datetime attribute for screen readers. Authors must set date
when displaying a specific moment; when omitted, the current time
is used. Authors should wrap relative timestamps in rh-tooltip
so users can see the full date. Avoid combining date-format and
time-format with customFormat as customFormat overrides both.
The element is not keyboard-focusable on its own.
Slots
0
Attributes
8
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
date-format
|
dateFormat |
Sets the date formatting style. When set without |
|
|
time-format
|
timeFormat |
Sets the time formatting style. When set without |
|
|
display-suffix
|
displaySuffix |
Appends custom text after the formatted timestamp string. Useful for displaying a timezone label (e.g. "US Eastern") when the built-in time format does not include one. |
|
|
locale
|
locale |
Overrides the browser's default locale for formatting. Accepts any valid BCP 47 language tag (e.g. "en-GB", "es", "ja"). Defaults to the browser's locale when not set. |
|
|
relative
|
relative |
When set, displays the timestamp as a relative time string
(e.g. "3 hours ago", "in 2 days") instead of an absolute date.
Uses |
|
|
utc
|
utc |
When set, converts the displayed time to UTC. If no |
|
|
hour-12
|
hour12 |
When set, uses 12-hour time format (e.g. "2:30 PM") instead of 24-hour time (e.g. "14:30"). Accepts the attribute values "true" or "false", or can be set as a boolean property. |
|
|
date
|
date |
The date value to display, as a date string parseable by |
|
|
Methods
0
None
Events
0
None
CSS Shadow Parts
0
None
CSS Custom Properties
0
None
Design Tokens
0
None
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.