Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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




// Node.js program to demonstrate the  
// Date.locale() APi
  
// Importing date-and-time module
const date = require('date-and-time')
  
// Getting the locale value
const value = date.locale();
  
// display the result
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




// Node.js program to demonstrate the  
// Date.locale() APi
  
// Importing date-and-time module
const date = require('date-and-time')
  
// Changing the local to es spanish
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

My Personal Notes arrow_drop_up
Recommended Articles
Page :