[英]How to get the date/time in a specific timezone?
I've been using moment.js to work with date/times in javascript. 我一直在使用moment.js在javascript中处理日期/时间。 My goal is to determine what time it is in PST regardless of where a user is.
我的目标是确定在PST中几点钟,无论用户身在何处。 I had been using this method:
我一直在使用这种方法:
var pstTime = moment().utc().subtract('hours', 7);
Which worked up until daylight savings time a few weeks back. 直到几周前的夏时制才起作用。 Now it is one hour off and causing some problems.
现在是一个小时的休假,并导致一些问题。 Is there a way (either in moment.js or standard JS) to just pull the time for a specific time zone?
有没有办法(在moment.js或标准JS中)将时间拉到特定时区?
您可以使用Moment时区 。
var pstTime = moment().tz('America/Los_Angeles');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.