Templating the Timestamp field
The Timestamp field allows content writers to add a date and time.
Here’s an example of how to retrieve the value of a Timestamp field. In this case, the Timestamp field has the API ID event_date.
Copy
var PrismicDOM = require('prismic-dom');
var eventTime = PrismicDOM.Date(document.data.event_date);
By saving the Timestamp value as a Date object, you can format it using the built-in locale format function. Using a library such as Moment.js could also be a good idea if it fits your needs.
Copy
var timestamp = PrismicDOM.Date(document.data.event_date);
var formattedTimestamp = Intl.DateTimeFormat('en-US',{
year: "numeric",
month: "short",
day: "2-digit",
hour: "numeric",
minute: "2-digit",
second: "2-digit"
}).format(timestamp);
// Outputs the date and time in Mon dd, YYYY, H:MM:SS AM/PM format