简体   繁体   English

使用toLocaleDateString在相同代码上的不同结果

[英]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.

相关问题 toLocaleDateString 使用相同的语言是不同的 - toLocaleDateString is different using the same language 日期输入和toLocaleDateString使用不同的语言环境 - Date input and toLocaleDateString using different locales Date.toLocaleDateString()在相同的操作系统和设置的不同浏览器中返回不同的输出 - Date.toLocaleDateString() return different output in different browsers same OS and settings 为什么我用相同的代码得到不同的结果? - Why I get different result with same code? 相同代码的两个版本返回不同的结果 - Two version of the same code returns different result 为什么相同的代码在jsfiddle中给出不同的结果 - Why the same code give different result in jsfiddle JavaScript中使用toLocaleDateString的日期格式 - Date Format in JavaScript using toLocaleDateString 使用相同输入数据的网站javascript代码如何根据访问者计算出不同的结果? - how can website javascript code using same input data compute a different result depending on visitor? Jscript在开发和测试机器上返回不同的(计算的)结果-使用相同的代码 - Jscript returning different (Calculated) result on Dev and Test machine - using same code Javascript vs C ++,相同的代码,不同的结果,为什么呢? - Javascript vs C++, same code, different result, why is that?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM