2017-05-15 16:23
浏览 71


I am dealing with time.Time objects that has been parsed with the wrong timezone. They internally have a UTC tz but the original data come from a legacy MySQL database that internally store datetimes with the timezone Europe/Paris.

I would like to change the internal timezone of the time without reparsing it. I have tried the time.In() function but it does not solve my use case because it return the same time for another timezone.

My ultimate solution would be to use to recreate the date from the value of the original with the proper location. However if this could be avoided this would be better.

Any thoughts ?


图片转代码服务由CSDN问答提供 功能建议

我正在处理time.Time对象,该对象已使用错误的时区进行了解析。 它们内部具有UTC tz,但原始数据来自旧的MySQL数据库,该数据库内部存储具有欧洲/巴黎时区的日期时间。

我想更改时间的内部时区,而无需 修复它。 我已经尝试过time.In()函数,但是不能解决用例,因为它会为另一个时区返回相同的时间。

我的最终解决方案是使用 从日期的值重新创建日期 原始位置正确。 但是,如果可以避免,那就更好了。



  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubai9014 2017-05-15 16:43

    Can you just Add a fixed offest to them?

    t,_ := time.Parse(...)
    t = t.Add(-4 * time.Hour) // or whatever offset makes it work
    // t is now correct utc time
    // In should work less badly:
    localTime := t.In(myRealLocation)
    解决 无用
    打赏 举报

相关推荐 更多相似问题