| 1 |
--- |
| 2 |
id: Timestamp |
| 3 |
section: components |
| 4 |
cssPrefix: pf-v6-c-timestamp |
| 5 |
propComponents: ['Timestamp', 'TimestampTooltip'] |
| 6 |
--- |
| 7 |
|
| 8 |
## Examples |
| 9 |
|
| 10 |
### Default |
| 11 |
|
| 12 |
By default, a timestamp will display the current date and time based on the current locale if the `date` prop is not passed in. |
| 13 |
|
| 14 |
Passing the `shouldDisplayUTC` property will display the UTC date and time instead of the current or passed in locale. |
| 15 |
|
| 16 |
```ts file="./TimestampDefault.tsx" |
| 17 |
|
| 18 |
``` |
| 19 |
|
| 20 |
### Basic formats |
| 21 |
|
| 22 |
The format of the displayed content can be customized by passing in the `dateFormat` and/or `timeFormat` props. Passing in only one of the props will display only the date or time, depending on which prop is passed in. The possible options are "full", "long", "medium", and "short". |
| 23 |
|
| 24 |
You can also pass in the `displaySuffix` prop to display a custom suffix at the end of the displayed content. This will not override a timezone that is already displayed from the applied time format. |
| 25 |
|
| 26 |
```ts file="./TimestampBasicFormats.tsx" |
| 27 |
|
| 28 |
``` |
| 29 |
|
| 30 |
### Custom format |
| 31 |
|
| 32 |
The format of the displayed content can be further customized by passing in the `customFormat` prop. Read [datetime format options](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options) for a list of options that can be passed in. |
| 33 |
|
| 34 |
```ts file="./TimestampCustomFormat.tsx" |
| 35 |
|
| 36 |
``` |
| 37 |
|
| 38 |
### Default tooltip |
| 39 |
|
| 40 |
To render a tooltip that displays the timestamp content as a UTC time, you can pass in the `tooltip` prop with a variant of "default". The format of the default tooltip content will match the format of the timestamp content. |
| 41 |
|
| 42 |
You can customize the suffix of this default tooltip variant by passing in `suffix` to the `tooltip` prop. |
| 43 |
|
| 44 |
```ts file="./TimestampDefaultTooltip.tsx" |
| 45 |
|
| 46 |
``` |
| 47 |
|
| 48 |
### Custom content |
| 49 |
|
| 50 |
To display custom content, such as a relative time or prefacing text, you can pass in content to the `children` prop. |
| 51 |
|
| 52 |
When also rendering a default tooltip with the `tooltip` prop, you can pass in the `dateFormat` and/or `timeFormat` props to customize the tooltip content without affecting the custom timestamp content. |
| 53 |
|
| 54 |
```ts file="TimestampCustomContent.tsx" |
| 55 |
|
| 56 |
``` |
| 57 |
|
| 58 |
### Custom tooltip |
| 59 |
|
| 60 |
By passing in `variant="custom"` and `content` to the `tooltip` prop, you can display custom content within the timestamp's tooltip. |
| 61 |
|
| 62 |
```ts file="TimestampCustomTooltip.tsx" |
| 63 |
|
| 64 |
``` |