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

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - Date toLocaleDateString in node

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

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

1 Answer

0 votes
by (71.8m points)

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?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...