当前位置:网站首页>读取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
边栏推荐
猜你喜欢

Remember using Ali Font Icon Library for the first time

2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展

编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)

MySQL 中的字符串函数
![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](/img/ed/4d61ce34f830209f5adbddf9165676.png)
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

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

C language loop structure program

Uniapp custom search box adaptation applet alignment capsule

Gets the time range of the current week

The ultimate experience, the audio and video technology behind the tiktok
随机推荐
Welcome to the markdown editor
String function in MySQL
Kubernetes 服务发现 监控Endpoints
Leak detection and vacancy filling (6)
2022年流动式起重机司机国家题库模拟考试平台操作
2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination
C1小笔记【任务训练篇二】
Fashion classification case based on keras
C# 的数据流加密与解密
C language array processing batch data
_ FindText error
ES6 face test questions (reference documents)
C1小笔记【任务训练篇一】
C#的随机数生成
Add drag and drop function to El dialog
C1 notes [task training part 2]
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
油猴网站地址
一些问题一些问题一些问题一些问题
Oil monkey website address