Node.js date-and-time Date.locale() Method
Last Updated :
26 Mar, 2021
The date-and-time.Date.locale() method is used to get or switch the locale from one into another language.
Required Module: Install the module by npm or used it locally.
By using npm:
npm install date-and-time --save
By using CDN link:
<script src="/path/to/date-and-time.min.js"></script>
Syntax:
locale(])
Parameters: This method takes the locale and code as a parameter.
Return Value: This method returns the current locale of the date and time object.
Example 1:
index.js
const date = require( 'date-and-time' )
const value = date.locale();
console.log( "current locale :- " + value)
|
Run index.js file using below command:
node index.js
Output:
current locale :- en
Example 2: Changing locale
Filename: index.js
index.js
const date = require( 'date-and-time' )
console.log( "Change local " +date.locale( 'es' ))
|
Run index.js file using below command:
node index.js
Output:
Change local es
Reference: https://github.com/knowledgecode/date-and-time#localecode-locale
Share your thoughts in the comments
Please Login to comment...