javascript - Moment.JS 显示指定时区的格式化时间

标签 javascript date momentjs

我正在尝试使用时刻时区显示当前命名时区的时间。

该时间以 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。

我用了http://www.epochconverter.com/

关于javascript - Moment.JS 显示指定时区的格式化时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24886906/

相关文章:

javascript - 在渲染 img html 组件时重定向或显示错误消息

php - 具有多个 div 的 Jquery UI 可拖动/可调整大小的容器

mysql - 如何从年份(列)结果中排除某些年份?

php - 如何组合从下拉列表中选择的日期/时间以在 MySQL 查询中使用?

sql - 查询在postgres中按降序对时间和日期进行排序

javascript - a s 的设置值 :hidden in javascript

javascript - 拦截键盘按下

javascript - 使用 moment timezone js 将日期字符串转换为带时区的日期

javascript - moment.js 中的 diff 比较操作

ruby-on-rails - 将 MomentJS 格式化为 Rails DateTime