0

在我的反应应用程序中,我使用 javascriptIntl.DateTimeFormat()以我需要的方式格式化日期和时间。链接到这个Intl.DateTimeFormat()

我想将相同格式的日期和时间移动到FormatJS Intl library.

我试图理解文档,但我不知道如何实现与使用Intl.DateTimeFormat().

这是一种方法的示例

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})`;
};

实际上,这取决于我们所拥有的时区的结果就是一个例子

19 Aug 2021, 02:00 (Europe/Stockholm)

所以我的问题是如何使用 FormatJs 库重现相同的内容并IntlShape显示相同的日期和时间

4

0 回答 0