Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I use toLocaleDateString in browser it returns

n = new Date()
n.toLocaleDateString()
"2/10/2013"

but in node.js the format is completely different

n = new Date()
> n.toLocaleDateString()
'Sunday, February 10, 2013'

How to get the browser's format (mm/dd/yy) in node.js?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
400 views
Welcome To Ask or Share your Answers For Others

1 Answer

For me, the solution was to install an additional module full-icu for node js full-icu-npm

And after in package.json insert:

{"scripts":{"start":"node --icu-data-dir=node_modules/full-icu YOURAPP.js"}}

or

In the current version of Node.js v10.9.0 is Internationalization Support. To control how ICU is used in Node.js, you can?configure?options are available during compilation. If the small-icu option is used you need to provide ICU data at runtime:

  • the?NODE_ICU_DATA?environment variable: ?env NODE_ICU_DATA=/some/directory node
  • the?--icu-data-dir?CLI parameter:? node --icu-data-dir=/some/directory?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...