javascript - Convert ISO/UTC date to local by displaying timezone javascript/momentjs
问题描述
I have a date in the format like 2019-05-18T19:30:00-0400 which I need to display as 05/18/2019 07:30 PM EST using momentjs or plain javascript. I tried several ways, for example, moment(new Date('2019-05-18T19:30:00-0400')).format('MM-DD-YYYY h:mm A zz')
解决方案
仅从偏移量是不可能确定时区的。有许多偏移量属于多个时区。因此,呈现缩写是不可能的。
有关详细信息,请参阅 timezone 标记 wiki 中的Time Zone != Offset ,如果您需要示例,请参阅tz 数据库时区列表。
但是,从您的评论来看,您似乎还希望保持与给定相同的本地时间和偏移量。Moment 可以使用它的(名称不恰当的)parseZone
函数来帮助解决这部分问题:
moment.parseZone("2019-05-18T19:30:00+0100").format("MM/DD/YYYY hh:mm A ZZ")
//=> "05/18/2019 07:30 PM +0100"
推荐阅读
- c# - 如何使用 Azure AD 在 WPF 应用程序中验证 Web api
- python - 如何连续更改文本颜色
- reactjs - 为什么相同数据下价格差异的百分比一直在变化?
- sql - 如何将复杂的表单/投票问题转换为 SQL 表?
- c++ - 如何使用 mingw32-make 在 Makefile 中正确包含外部头文件?
- javascript - 有什么方法可以知道点击了哪个按钮?
- terraform - 无法使用 terraform 获取 VM 的 vSphere Instance UUID
- django - 管理面板实例视图中的标签输入字段
- angular - 为什么 Angular 应用程序只能从 spring 服务器下载一些 svg 文件
- django - 将列名更改为当前月份