Date Templating with Javascript

The Date field allows content writers to add a date that represents a calendar day.

Default Format

Here's an example of how to access a Date value using the PrismicDOM.date object.

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

var date = PrismicDOM.Date(document.data.postDate);

Custom Format

By saving the Date 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 date = PrismicDOM.Date(document.data.postDate);

var formattedDate = new Intl.DateTimeFormat('en-US',{
  year: "numeric",
  month: "short",
  day: "2-digit"
}).format(date);
// Outputs the date in Mon dd, YYYY format