使用moment(timezone).js从用户浏览器获取时区 [英] Get timezone from users browser using moment(timezone).js

查看:895
本文介绍了使用moment(timezone).js从用户浏览器获取时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用moment.js和moment-timezone.js时,获取客户端时区并将其转换为其他时区的最佳方法是什么

What is the best way to get client's timezone and convert it to some other timezone when using moment.js and moment-timezone.js

我想找出客户的时区是什么,然后将其日期和时间转换为其他时区.

I want to find out what is clients timezone and later convert his date and time into some other timezone.

有人对此有经验吗?

推荐答案

var timedifference = new Date().getTimezoneOffset();

这将返回与UTC时间与客户端时区的时差. 然后,您可以随心所欲地玩它.

This returns the difference from the clients timezone from UTC time. You can then play around with it as you like.

这篇关于使用moment(timezone).js从用户浏览器获取时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆