date-fns 的多语言环境支持

Multiple locale support with date-fns

在版本 2.0.0-alpha.11 中使用 date-fns,我试图获得与以下 momentjs 调用相同的行为:

moment().format('LL');   // July 26, 2018
moment().format('LLL');  // July 26, 2018 4:59 PM

我试过的是:

import format from 'date-fns/esm/format';
const formattedDate = format(new Date(2018, 6, 26, 16, 59, 0), 'LL');

在那种情况下 formattedDate returns 月数 07

在语言环境的源代码中,有definitions for short, medium, long and full format。有没有办法根据当前语言环境使用 format 函数获取这些定义?

我看过 documentation and at the release notes 但找不到方法。

深入查看源码后,找到解决方案:

moment().format('LL');  ==> format(new Date(), 'PP');
moment().format('LLL'); ==> format(new Date(), 'PPp');

输出并不严格等同于 momentjs 但在我的情况下足够接近。