我正在使用 Discord.js 在 NodeJS 中开发一个 Discord 机器人,我想解析格式为“YYYY-MM-DD”的日期并以长 fr-FR 格式显示。
我试过了:
var dateSortie = new Date("2018-06-03");
var options = {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
};
console.log(dateSortie.toLocaleDateString("fr-FR", options));
无论语言环境如何(fr-Fr、de-De、...),它总是返回 "2018 M06 3, Sun"
。
最佳答案
采购自 this GitHub 问题:
By default
--with-intl=small-icu
is used to build node, which contains just the en-US locale [...]. You will need to either build node with--with-intl=full-icu
or--with-intl=system-icu
if you want to be able to use more locales. The reason node is built with a smaller ICU by default is file size.
除了构建您自己的 Node 版本之外,另一种方法似乎是安装 full-icu
模块。
关于javascript - toLocaleDateString 返回字符串而不关心语言环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50615208/