Templating the Timestamp field

The Timestamp field allows content writers to add a date and time.


Before Reading

This article assumes the following:

1. That you have saved the document object in a variable named document as shown in the Retrieve the document object page.

2. That you have included the prismic-dom library as a dependency in your project.

Access the default Timestamp string

Here is an example that shows how to access the Timestamp field value as the default string. In this case the Date field has the API ID of event_date.

Copy
const eventTime = document.event_date;

Convert the date to a DateTime object

Here's an example of how to convert the Date string to a DateTime object using the PrismicDOM.date() function. In this case, the Date field has the API ID of event_date.

Copy
const PrismicDOM = require('prismic-dom');

const dateObject = PrismicDOM.Date(document.event_date);