Open In App

Node.js date-and-time Date.locale() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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


Last Updated : 26 Mar, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads