admin管理员组文章数量:1315792
I'm using this code.:
date.toLocaleDateString('pt-BR')
- In my chrome browser the result is.: 9/13/2016
- When I run the tests in local.: 2016-09-13
- When I runt the tests in Circle CI.: 9/13/2016
What it happens?
Ps.: I'm using Jest and JSDom for my tests.
I'm using this code.:
date.toLocaleDateString('pt-BR')
- In my chrome browser the result is.: 9/13/2016
- When I run the tests in local.: 2016-09-13
- When I runt the tests in Circle CI.: 9/13/2016
What it happens?
Ps.: I'm using Jest and JSDom for my tests.
Share Improve this question asked Jan 24, 2017 at 13:29 Bruno QuaresmaBruno Quaresma 10.7k7 gold badges38 silver badges51 bronze badges 2-
try
new Intl.DateTimeFormat('pt-BR').format(date)
Also, check this link – Tareq Commented Jan 24, 2017 at 13:35 - toLocaleDateString is not supported in some of your environments. See this issue. – Robin Wieruch Commented Jan 20, 2021 at 8:16
3 Answers
Reset to default 8Use the toLocaleDateString
options for set a fixed format.
var date = new Date();
var options = { year: 'numeric', month: '2-digit', day: '2-digit' };
console.log(date.toLocaleDateString('pt-BR', options));
You can add "LC_ALL="en_US.UTF-8" in the param test in package.json to fix it
"test": "LC_ALL=\"en_US.UTF-8\" npm run test",
Why do not use moment.js? It's simple and minimalist library to handle dates server side and client side, locales depend on the system and few things more, use moment and you will be sure the correct format moment.js
本文标签: javascripttoLocaleDateString is different using the same languageStack Overflow
版权声明:本文标题:javascript - toLocaleDateString is different using the same language - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741991242a2409149.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论