douxiexie3574 2017-05-15 16:23
浏览 78


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 ?


  • 写回答

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)
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 VB6.0中PICTUREBOX加载本地图片无法显示
    • ¥100 关于游戏app session获取的问题
    • ¥15 MYSQL数据库建表
    • ¥15 爬虫程序爬取TTGChina网站文章代码
    • ¥35 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。
    • ¥15 如何用下图方法在AMESim中搭建离心泵模型
    • ¥15 C#连接服务器,请求时报Ssl/Tsl未能建立安全通道
    • ¥15 xcode15build的c++ dylib在10.15上不兼容
    • ¥15 CPLD如何实现在线逻辑分析
    • ¥15 控制面板卸载无权限!!