简体   繁体   中英

How to get the date/time in a specific timezone?

I've been using moment.js to work with date/times in javascript. My goal is to determine what time it is in PST regardless of where a user is. 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时区

var pstTime = moment().tz('America/Los_Angeles');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM