Skip to main content

Handling dates/times

By default, all indications of time in EVA Core are provided as UTC times. In your front ends however, you often want to format the date/time according to either the user's location, or some organization unit's location.

Standard format

Dates in EVA are formatted as YYYY-MM-DDTHH:mm:ss.ss.

  • YYYY-MM-DD is the date: year-month-day.
  • The character "T" is used as the delimiter.
  • HH:mm:ss.ss is the time: hours, minutes, seconds and milliseconds.

User context

In order to format dates in a user context, we need the user's 'locale' (eg. en-GB):

const date = new Date("2022-12-08T13:28:00.000Z");

console.log(
new Intl.DateTimeFormat("en-US", {
dateStyle: "full",
timeStyle: "medium"
}).format(date)
);

This formats the date/time into a customary format for that locale.

Result:

Thursday, December 8, 2022 at 11:28:00 PM GMT+11

However, this is not the correct time for the US. Locale only adjusts the format, not the value.

In order to get the correct value for our timezone, we have to provide a timezone.

Timezone context

const date = new Date("2022-12-08T13:28:00.000Z");

console.log(
new Intl.DateTimeFormat("en-US", {
dateStyle: "full",
timeStyle: "medium",
timeZone: "America/New_York"
}).format(date)
);

Result:

Thursday, December 8, 2022 at 8:28:00 AM