[英]Different result on same code using toLocaleDateString
I am trying to set a date to my culture (fr-FR) using node and javascript. 我正在尝试使用节点和JavaScript为我的文化(fr-FR)设置日期。 I found a good method on mozilla website: 我在mozilla网站上找到了一个不错的方法:
var event = new Date();
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
console.log(event.toLocaleDateString('fr-FR', options));
// Result is "samedi 8 juin 2019"
It is working on the website ( https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Date/toLocaleDateString)but when i use this code in my node server, the result is totally different: 它正在网站( https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Date/toLocaleDateString )上运行,但是当我在节点服务器中使用此代码时,结果完全不同:
2019 M06 8, Sat
What am i missing please? 我想念什么?
Nodejs by default only contains the en-US locale ( see here ), You can fix it by add full-icu-npm to dependency: 默认情况下,Node.js仅包含美国语言环境( 请参阅此处 ),您可以通过将full-icu-npm添加到依赖项来修复它:
npm install --save full-icu
And then add flag to npm script: 然后将标志添加到npm脚本:
For package.json:
{"scripts":{"start":"node --icu-data-dir=node_modules\\full-icu YOURAPP.js"}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.