当前位置:网站首页>读取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
边栏推荐
- Submit local warehouse and synchronize code cloud warehouse
- EasymodbusTCP之clientexample解析
- Implementation of image recognition code based on VGg convolutional neural network
- JS parsing and execution process
- 31. Next arrangement
- undefined reference to `Nabo::NearestNeighbourSearch
- Dry goods | how to extract thumbnails quickly?
- 2022年上海市安全员C证操作证考试题库及模拟考试
- Leak detection and vacancy filling (6)
- 编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
猜你喜欢

C language loop structure program

SystemVerilog (VI) - variable

470. Rand10() is implemented with rand7()

394. String decoding - auxiliary stack

Client example analysis of easymodbustcp

.105Location

C network related operations

cv_ Solution of mismatch between bridge and opencv

Go's gin framework learning

JS forms the items with the same name in the array object into the same array according to the name
随机推荐
Future usage details
Uniapp custom search box adaptation applet alignment capsule
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
I / O multiplexing and its related details
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
Leak detection and vacancy filling (VIII)
C network related operations
Go对文件操作
Sword finger offer 22 The penultimate node in the linked list - speed pointer
Implementation of object detection case based on SSD
Go's gin framework learning
Submit local warehouse and synchronize code cloud warehouse
The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time
ES6 new method
ROS package NMEA_ navsat_ Driver reads GPS and Beidou Positioning Information Notes
Yolov4 pruning [with code]
cv_ Solution of mismatch between bridge and opencv
Classification of cifar100 data set based on convolutional neural network
394. String decoding - auxiliary stack
2022年茶艺师(初级)考试模拟100题及模拟考试