我正在尝试使用时刻时区显示当前命名时区的时间。
该时间以 UTC 格式存储在数据库中,为 2014-07-22 11:11:06。无论我尝试什么,即使指定的时区是欧洲/伦敦,我也无法将时间显示为 12:11。
var timestamp = 1406023866000; // converted from database stored as UTC 2014-07-22 11:11:06
var zone = tz.name(); // Europe/London
var utc = moment(timestamp); // create a moment from the timestamp
var time = utc.tz(zone); // _d: Date {Tue Jul 22 2014 12:11:06 GMT+0100 (GMT Standard Time)}
// _f: undefined
// _i: 1406023866000
formatted = time.format('h:mma'); // 11:11am - should be 12.11pm because of BST
最佳答案
假设您的时间戳以毫秒为单位,1406023866000 = GMT: Tue, 22 Jul 2014 10:11:06 GMT。
关于javascript - Moment.JS 显示指定时区的格式化时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24886906/