当前位置:网站首页>读取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
边栏推荐
- 20222 return to the workplace
- ROS package NMEA_ navsat_ Driver reads GPS and Beidou Positioning Information Notes
- 31. Next arrangement
- SystemVerilog(六)-变量
- C1 notes [task training chapter I]
- Flask项目的部署详解
- Fashion classification case based on keras
- 2021 Great Wall Cup WP
- Dry goods | how to extract thumbnails quickly?
- Ring back to origin problem - byte jumping high frequency problem
猜你喜欢
Chrome浏览器的跨域设置----包含新老版本两种设置
Operators in C language
QTableWidget使用讲解
An example of linear regression based on tensorflow
Yolov4 pruning [with code]
48. Rotate image
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
Operation of 2022 mobile crane driver national question bank simulation examination platform
Romance in C language
394. String decoding - auxiliary stack
随机推荐
31. Next arrangement
极致体验,揭晓抖音背后的音视频技术
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
云原生虚拟化:基于 Kubevirt 构建边缘计算实例
Index: teach you index from zero basis to proficient use
Amount input box, used for recharge and withdrawal
C1小笔记【任务训练篇一】
Error in created hook: "referenceerror:" promise "undefined“
Examination question bank and online simulation examination of the third batch (main person in charge) of special operation certificate of safety officer a certificate in Guangdong Province in 2022
2022 tea artist (primary) examination simulated 100 questions and simulated examination
C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
I / O multiplexing and its related details
SystemVerilog (VI) - variable
402. Remove K digits - greedy
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
k8s之实现redis一主多从动态扩缩容
MySQL advanced index [classification, performance analysis, use, design principles]
Write a regular
C network related operations
Notes on common basic usage of eigen Library