I've found a lot of good info on using Date() and getting timezones, but something just isn't working. I have my GraphQL (sourcing from Sanity) set to use formatString, like this:
export default function MinutesItemGrid() {
const { minutes } = useStaticQuery(graphql`
query {
minutes: allSanityMinutes {
nodes {
endTime(formatString: "h:mma [on] MM/DD/YYYY")
}
}
}
`);
Then calling it in a .map
:
const allMinutes = minutes.nodes;
return (
<CardStyles>
{allMinutes.map((minute) => (
<ItemStyles>
<div className="card" key={minute.id}>
<div className="content">Meeting began at: {minute.endTime}</div>
</div>
</ItemStyles>
))}
</CardStyles>
);
Which displays as 11:33pm on 10/14/2020. That is 6 hours ahead of what it should be.
I know this returns UTC time standardly. I know how to get the local time offset (new Date().getTimezoneOffset();
) and get the local timezone (Intl.DateTimeFormat().resolvedOptions().timeZone
), but I don't see an option to change the timezone to display to MST (or local time) instead of UTC. I have tried subtracting the 6 hours in various ways, tried using moment.js and moment.js timezone to change the timezones based on their docs. I've just found out that Luxon is a better option now, but even in their docs I don't see a resolution when pulling the data from GraphQL.