当前位置:网站首页>读取excel,int 数字时间转时间
读取excel,int 数字时间转时间
2022-04-23 17:57:00 【用户昵称不能为空】
golang解析excel的时候,会发现日期时间都变成了 数字,但在excel中显示是正常的。
原因
excel中的日期按照他自有的纪元存储。以 1899年12月30日0时0分0秒UTC为纪元。
解决办法
转换
func ExcelIntDate(dateStr string) (dt time.Time, err error) {
var dateValue float64
matched, err := regexp.MatchString(`^\d+$`, dateStr)
if err != nil {
return
}
if !matched {
err = errors.New("not excel time")
return
}
dateValue, err = strconv.ParseFloat(dateStr, 64)
if err != nil {
return
}
epoch := time.Date(1899, 12, 30, 0, 0, 0, 0, time.UTC) // UTC 1899/12/30 00:00:00
dt = epoch.Add(time.Duration(dateValue) * 24 * time.Hour)
return
}
测试
var dateStr string
dateStr = "44666" // 2022-04-15 00:00:00 +0000 UTC
dateStr = "44621" // 2022-03-01 00:00:00 +0000 UTC
fmt.Println(ExcelIntDate(dateStr))
版权声明
本文为[用户昵称不能为空]所创,转载请带上原文链接,感谢
https://blog.csdn.net/default7/article/details/124319907
边栏推荐
- .105Location
- How to read literature
- MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
- 2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination
- Using files to save data (C language)
- 2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
- 470. Rand10() is implemented with rand7()
- 开源按键组件Multi_Button的使用,含测试工程
- 油猴网站地址
- 48. Rotate image
猜你喜欢
JS high frequency interview questions
Cross domain settings of Chrome browser -- including new and old versions
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
Implementation of k8s redis one master multi slave dynamic capacity expansion
48. Rotate image
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
Uniapp custom search box adaptation applet alignment capsule
Auto.js 自定义对话框
极致体验,揭晓抖音背后的音视频技术
高德地图搜索、拖拽 查询地址
随机推荐
402. Remove K digits - greedy
The method of changing a value in the array and a value in the object of wechat applet
Eigen learning summary
This point in JS
JS interview question: FN call. call. call. Call (FN2) parsing
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
Go file operation
MySQL_01_简单数据检索
JS parsing and execution process
31. Next arrangement
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
Error in created hook: "referenceerror:" promise "undefined“
Timestamp to formatted date
Write a regular
Chrome浏览器的跨域设置----包含新老版本两种设置
QTableWidget使用讲解
Go的Gin框架学习
cv_ Solution of mismatch between bridge and opencv
Tell the truth of TS
Client example analysis of easymodbustcp