惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 雨V幕

使用chromedp 来做人工模拟操作爬取数据方法 遍历redis按照前缀给未设置过期时间的数据添加过期时间 使用rabbitmq 进行任务调度 使用trace进行排查网络瓶颈 使用vscode 调试 Python 使用power shell 拆分 csv文件 将大文件拆分成小文件。 使用postman 添加预处理验签。 go 使用pprof 进行问题排查 Mysql无主键删除重复数据的快速方法 解决mysql 事务死锁的方法 go在处理批量下载时候出现fatal error: runtime: out of memory AnalyticDB 创建db clickhouse 进行建表期间的一些优化 kraots2.0 在windows 环境搭建开发环境 Sql Server使用函数获取拼音码 关于async 和await关键字 使用kubespray 一键部署 containerd 的安装和熟悉 VMware 配置双网卡实现上网和固定ip
go 序列化反序列化之后时区信息丢失
雨V幕 · 2024-03-11 · via 博客园 - 雨V幕
  •  编写了获取当前datetime 时间的方法如下
    // GetCurrentDateString 获取当天的时间date
    func GetCurrentDateString() time.Time {
        // 获取当前时间
        currentTime := time.Now().Local()
        // 格式化日期为字符串
        dateString := currentTime.Format(time.DateTime)
        resultTime, _ := time.Parse(time.DateTime, dateString)
        return resultTime
    }

    插入db之后发现时间+8了。

  • 造成以上原因是因为反序列化之后时区信息丢失了。所以没有时区的时候time到db用的是国际时间。所以跟北京/上海时间大致会相差8h
  • 解决方案 反序列化的时候代码改成 : 
    // GetCurrentDateString 获取当天的时间date
    func GetCurrentDateString() time.Time {
        // 获取当前时间
        currentTime := time.Now().Local()
        // 格式化日期为字符串
        dateString := currentTime.Format(time.DateTime)
        resultTime, _ := time.ParseInLocation(time.DateTime, dateString, time.Local)
        return resultTime
    }
  • 如果时间字符串中带了时区信息才去使用 time.Parse,否则使用 time.ParseInLocation
  • 排查db 和本地时间对不上的思路方案:
    • 检查链接字符串是否添加时区信息  例如 : parseTime=true&loc=Local
    • 检查服务器当前时区 是否正确: timedatectl | grep "Time zone"
    • 检查mysql 时区设置:SHOW VARIABLES LIKE '%time_zone%';
    • 阿里云AnalyticDB实例Datatime 类型最多精确到秒。使用TIMESTAMP可以存储'2024-03-11 15:22:11.4688249' 。 使用起来和Mysql实例有差距