Timestamp Templating with Javascript

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

Default Format

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.

var PrismicDOM = require('prismic-dom');

var eventTime = PrismicDOM.Date(document.data.event_date);

Custom Format

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.

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"
// Outputs the date and time in Mon dd, YYYY, H:MM:SS AM/PM format