[英]How do I set my default timezone to Ireland/dublin in javascript
I want to convert to my timezone to ireland/Dublin ,currently its taking my system time. 我想将时区转换为爱尔兰/都柏林,目前占用系统时间。 I have a different timezone.
我有不同的时区。
Like 12:37 PM local time to 7:00 AM (Ireland time) 像当地时间12:37 PM到7:00 AM(爱尔兰时间)
I know in php it is very easy by using date_default_timezone_set('Ireland/Dublin'); 我知道在php中使用date_default_timezone_set('Ireland / Dublin')很容易。
Is it possible via javascript? 是否可以通过javascript?
first you can get the local time with Date
. 首先,您可以使用
Date
获得当地时间。 Then convert it to UTC time by adding the timezone offset to local time. 然后,通过将时区偏移量添加到本地时间,将其转换为UTC时间。 you can get the utc as follows:
您可以按以下方式获取utc:
var offset = new Date().getTimezoneOffset() * 60000;
utc = localTime + offset ;
then add the Ireland offset ie +1 hour in milliseconds to the utc time. 然后将爱尔兰偏移量(即+1小时,以毫秒为单位)添加到utc时间。
you can refer: http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329 您可以参考: http : //www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.