在JavaScript中显示带有日期对象的亚洲和美洲日期时间
为此,您可以使用JavaScript中的timeZone,即分别用于亚洲和美国的特定时区。
对于亚洲时区
var todayDateTime = new Date().toLocaleString("en-US", {timeZone:
"Asia/Kolkata"});对于美国时区
var americaDateTime = new Date().toLocaleString("en-US", {timeZone:
"America/New_York"});示例
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);要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo193.js。
输出结果
这将产生以下输出-
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
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短