当前位置:网站首页>读取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
边栏推荐
- JS implementation private attribute
- Sword finger offer 22 The penultimate node in the linked list - speed pointer
- Fashion classification case based on keras
- C#字节数组(byte[])和字符串相互转换
- Go language JSON package usage
- Utilisation de la liste - Ajouter, supprimer et modifier la requête
- 198. Looting - Dynamic Planning
- Romance in C language
- 列錶的使用-增删改查
- Clion installation tutorial
猜你喜欢

Operators in C language

Classification of cifar100 data set based on convolutional neural network

YOLOv4剪枝【附代码】

440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question

Auto.js 自定义对话框

JS high frequency interview questions
![C1 notes [task training part 2]](/img/10/48f7490a6c097f2b178ae948cb2c91.png)
C1 notes [task training part 2]

2022制冷与空调设备运行操作判断题及答案

2022年上海市安全员C证操作证考试题库及模拟考试

高德地图搜索、拖拽 查询地址
随机推荐
【Appium】通过设计关键字驱动文件来编写脚本
Eigen learning summary
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
An example of linear regression based on tensorflow
Timestamp to formatted date
Detailed deployment of flask project
Transfer learning of five categories of pictures based on VGg
[appium] write scripts by designing Keyword Driven files
Write a regular
239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
[binary number] maximum depth of binary tree + maximum depth of n-ary tree
Go language JSON package usage
102. Sequence traversal of binary tree
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
MySQL advanced index [classification, performance analysis, use, design principles]
Random number generation of C #
Operation of 2022 mobile crane driver national question bank simulation examination platform
Flask项目的部署详解
Arithmetic expression