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?
The toLocaleDateString() method returns a string with a language-sensitive representation of the date portion of the specified date in the user agent's timezone.
Use the toLocaleString() method to get a date and time in the user's locale format, e.g. date. toLocaleString() . The toLocaleString method returns a string representing the given date according to language-specific conventions.
The toLocaleTimeString() method returns a string with a language-sensitive representation of the time portion of the date. In implementations with Intl. DateTimeFormat API support, this method simply calls Intl. DateTimeFormat .
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:
env NODE_ICU_DATA=/some/directory node
node --icu-data-dir=/some/directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With