Show a simple timestamp anywhere in your app!


Live Demo

When to use #

The Timestamp component renders a simple string showing a date and time. It is shown in an opinionated format that we believe is well suited for messages.

You can use this as a building block alongside other Cord components to build any message layout that you might need. Any timestamps returned from our APIs can be directly passed in and displayed correctly. For example, timestamps returned from our Message REST API.


How to use #

React:
import { Timestamp } from "@cord-sdk/react";

export const Example = () => {
  // Hour ago from current time
  const dateValue = new Date(Date.now() - 1000 * 60 * 60);

  return <Timestamp value={dateValue} />;
};
Vanilla JavaScript:
<script>
  // Hour ago from current time
  const dateValue = new Date(Date.now() - 1000 * 60 * 60);

  const timestamp = document.createElement('cord-timestamp');

  timestamp.setAttribute('value', dateValue);
  document.body.appendChild(timestamp);

</script>
import { Timestamp } from "@cord-sdk/react";

export const Example = () => {
  // Hour ago from current time
  const dateValue = new Date(Date.now() - 1000 * 60 * 60);

  return <Timestamp value={dateValue} />;
};
Copy

Properties #


value #

optional
string | number | Date
The timestamp to display. This can be any format that will be parsed properly by the Date constructor.
The default value is the current time and date.


relative #

optional
boolean
When true, timestamps are shown relative to the current time. When false, timestamps are shown in absolute terms.
The default value is set to true.

CSS customization #

If you want to customize this component, you can target the classes below in your app's CSS. These are guaranteed to be stable.

Class nameDescription
.cord-timestamp
Applied to the p containing the timestamp

Not finding the answer you need? Ask our Developer Community

Ask Cordy