当前位置:网站首页>读取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
边栏推荐
- Data stream encryption and decryption of C
- C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
- undefined reference to `Nabo::NearestNeighbourSearch
- Add animation to the picture under V-for timing
- Applet learning notes (I)
- On the method of outputting the complete name of typeID from GCC
- Chrome浏览器的跨域设置----包含新老版本两种设置
- Clion installation tutorial
- 关于gcc输出typeid完整名的方法
- Transfer learning of five categories of pictures based on VGg
猜你喜欢
Error in created hook: "referenceerror:" promise "undefined“
QTableWidget使用讲解
Logic regression principle and code implementation
C1小笔记【任务训练篇二】
Transfer learning of five categories of pictures based on VGg
Classification of cifar100 data set based on convolutional neural network
In JS, t, = > Analysis of
Data stream encryption and decryption of C
2022年茶艺师(初级)考试模拟100题及模拟考试
Random number generation of C #
随机推荐
386. Dictionary order (medium) - iteration - full arrangement
Amount input box, used for recharge and withdrawal
Build openstack platform
cv_ Solution of mismatch between bridge and opencv
undefined reference to `Nabo::NearestNeighbourSearch
Fashion classification case based on keras
C network related operations
Utilisation de la liste - Ajouter, supprimer et modifier la requête
C language array processing batch data
Arithmetic expression
Add animation to the picture under V-for timing
2021 Great Wall Cup WP
Commonly used functions -- spineros:: and spineros::)
Implementation of image recognition code based on VGg convolutional neural network
土地覆盖/利用数据产品下载
C#的随机数生成
Auto.js 自定义对话框
Go语言JSON包使用
Element calculation distance and event object
Flask项目的部署详解