前端获取时区
在前端中,可以使用JavaScript的Date对象来获取当前时区的时间。
·
在前端中,可以使用JavaScript的Date对象来获取当前时区的时间。
代码示例:
const now = new Date();
const localTime = now.toLocaleTimeString();
const localDate = now.toLocaleDateString();
console.log(`Local time is ${localTime} on ${localDate}`);
这段代码会输出当前时区的时间和日期,例如:
Local time is 11:30:00 AM on 9/28/2021
如果需要获取UTC时间,可以使用以下代码:
const now = new Date();
const utcTime = now.toUTCString();
console.log(`UTC time is ${utcTime}`);
这段代码会输出当前UTC时间,例如:
UTC time is Tue, 28 Sep 2021 03:30:00 GMT
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)