Total Newbie Question Re: Dates

I am working on a blog that originated from this repo GitHub - prismicio/nextjs-blog

When I enter a date in Prismic it comes out 1 day later on Nextjs? So if I post today. It will be dated 14 March 2021.

If I post tomorrow, it will has today's date. Is the date I'm authoring set to a different timezone than I am in?

Hey @brooks ,

Welcome to the Prismic community forum, and thanks for posting this question :slight_smile:

My first question is: are you using a date field, a timestamp field, or the published_date in the post metadata?

My second question is: how are you rendering the date? Are you using Prismic's date method?

Thank you for your reply Sam.

My date field JSON looks like this, I believe this is just a "date" field and not the metadata.

"title" : {
  "type" : "StructuredText",
  "config" : {
    "single" : "heading1",
    "label" : "Title",
    "placeholder" : "Blog Post Title..."
  }
},
"date" : {
  "type" : "Date",
  "config" : {
    "label" : "Date"
  }
},

The data is rendered with this component:

import React from 'react'
import { Date } from 'prismic-reactjs'

/**

  • Post list item date component
    */

const PostDate = ({ date }) => {
// Format the date to M d, Y
const dateFormat = {
month: 'short',
day: '2-digit',
year: 'numeric'
}
const displayDate = new Intl.DateTimeFormat('en-US', dateFormat).format(Date(date))

return (


{displayDate}


)
}

export default PostDate

Hey @brooks,

It's possible that this might be a quirk of JavaScript dates. Dates from the Prismic API are 00:00 UTC. This blog post explains why JavaScript dates are often off by one day. I can recreate the same error on my computer, and solve it like so:

const displayDate = new Intl.DateTimeFormat('en-US', dateFormat).format(Date(date + " GMT-4"))

Let me know if that helps!

Sam

1 Like

This issue has been closed as it has been fixed, Flag if it is not the case for you to reopen.