Display the Asian and American Date Time with Date Object in JavaScript

JavascriptWeb DevelopmentObject Oriented Programming

For this, you can use timeZone from JavaScript i.e. specific time zones for Asia and America respectively.

For Asian Time Zone

var todayDateTime = new Date().toLocaleString("en-US", {timeZone:
"Asia/Kolkata"});

For American Time Zone

var americaDateTime = new Date().toLocaleString("en-US", {timeZone:
"America/New_York"});

Example

var todayDateTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"});
todayDateTime = new Date(todayDateTime);
console.log("The Asia Date time is=");
console.log(todayDateTime)
var americaDateTime = new Date().toLocaleString("en-US", {timeZone: "America/New_York"});
americaDateTime = new Date(americaDateTime);
console.log("The America Date time is=");
console.log(americaDateTime);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo193.js.

Output

This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo193.js
The Asia Date time is= 2020-08-08T08:44:50.000Z
The America Date time is= 2020-08-07T23:14:50.000Z
raja
Published on 14-Sep-2020 08:38:36
Advertisements