In my react app I used the javascript Intl.DateTimeFormat() to format date and time in the way I need. Link to this Intl.DateTimeFormat()
I would like to move the same formatted date and time to the FormatJS Intl library.
I tried to understand the documentation but I have no idea how to achieve the same as was done using Intl.DateTimeFormat().
This is an example of one method
const ZoneDateTime = ({ dateTime, timeZone }) => {
let locale;
if (timeZone.includes('Europe')) locale = 'en-SE';
if (timeZone.includes('America')) locale = 'en-US';
if (timeZone.includes('Etc')) locale = 'en-EN';
if (timeZone.includes('Europe/London')) locale = 'en-GB';
const formatter = Intl.DateTimeFormat(locale, {
timeZone,
year: 'numeric',
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
});
return formatter.format(dateTime) + ` (${timeZone})`;
};
Practically the result of this depending of what timezone we have is an example
19 Aug 2021, 02:00 (Europe/Stockholm)
So my question is how to reproduce the same using the FormatJs library and IntlShape to show the same date and time