javascript - Momenjs 格式化程序将时间从 00 更改为 03 小时
问题描述
为什么moment("2020-08-26T00:00:00Z").format('DD.MM.YYYY HH:mm:ss Z')
给出“26.08.2020 03:00:00 +03:00”。我确实了解当前时区的添加,但为什么时间也会改变?
解决方案
在 ISO 8601 格式中,末尾的“Z”指的是 UTC+0 时区。2020-08-26T00:00:00Z
因此与 相同2020-08-26T00:00:00+00:00
。
如果要在构造函数中使用另一个时区,请显式指定它:
moment('2020-08-26T00:00:00+03:00').format('DD.MM.YYYY HH:mm:ss Z')
// ^^^^^^
// if the user agent's timezone is UTC+3,
// this will be formatted as "26.08.2020 00:00:00 +03:00"
另一方面,如果您想构建一个 UTC+0 日期时间并将其格式化为 UTC+0,忽略用户代理的 timezone,请使用它(根据您的评论):
moment("2020-08-26T00:00:00Z").utc().format("DD.MM.YYYY HH:mm:ss Z")
// ^^^^^^
// this will _always_ be formatted as "26.08.2020 00:00:00 +00:00"
推荐阅读
- javascript - 按给定顺序对数据表的列进行排序
- ruby-on-rails - Docker-compose Rails 后端 + postgresql 无法将主机名“db”转换为地址:名称或服务未知
- python - python函数输入参数中的空格,因为它是一个cython函数?
- jenkins - 在多分支管道中禁用分支并使用扫描事件重新打开
- javascript - 查找具有重复项的两个数组中的差异
- java - Spring - 根据数据库决定配置文件
- microsoft-graph-api - 使用 Bot 向 Microsoft Teams 会议发送消息
- html - 如何导出 pdf 或发送包含包含边框的 html 的电子邮件?
- react-native - 在设置 redux 状态后呈现经过身份验证和未经身份验证的条件堆栈导航器
- python - 为什么滚动与我的网页抓取效果不佳?