Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 960
evfwcqcg Avatar asked Feb 09 '13 23:02

evfwcqcg


People also ask

What is toLocaleDateString?

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.

How do you get a date from toLocaleString?

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.

What is toLocaleTimeString () in JavaScript?

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 .


1 Answers

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

like image 83
Rndmax Avatar answered Sep 24 '22 20:09

Rndmax