I am trying to format a date such that it always shows as UTC e.g. in the format 'dd/mm/YYYY HH:MM UTC'. So far I have this code:
const options = {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timezone: 'UTC',
timeZoneName: 'short'
};
const formattedTime = new Intl.DateTimeFormat('en-GB', options).format(new Date(unixTimestamp))
However this gives me a time in either GMT or BST, e.g.
24/11/2021, 05:51 GMT
27/10/2021, 05:09 BST
What I would like is for the time to be always shown as UTC so in the case of the above examples:
24/11/2021, 05:51 UTC
27/10/2021, 04:09 UTC
Is there a way to configure DateTimeFormat to do this or should I be using something else? I'd rather not resort to importing a library if at all possible.
The timezone property of the formatting options object must be in camelCase - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#timezone