1 Star 0 Fork 0

Eriloan / goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
time.go 575 Bytes
一键复制 编辑 原始数据 按行查看 历史
Eriloan 提交于 2022-03-23 18:05 . 修改依赖库引用
package os
import (
"fmt"
"strconv"
"time"
)
const (
NanosecondLen = 19
MillisecondLen = 13
SecondLen = 10
)
//TimestampToTime 时间戳转换
func TimestampToTime(timestamp int64) (t time.Time, err error) {
tmpStr := strconv.FormatInt(timestamp, 10)
tmpStrLen := len(tmpStr)
switch tmpStrLen {
case NanosecondLen:
t = time.Unix(0, timestamp)
return
case MillisecondLen:
t = time.Unix(0, timestamp*int64(time.Millisecond))
return
case SecondLen:
t = time.Unix(timestamp, 0)
return
}
err = fmt.Errorf("%s", "Invalid parameter.")
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shibingli/goutils.git
git@gitee.com:shibingli/goutils.git
shibingli
goutils
goutils
v1.2.5

搜索帮助

344bd9b3 5694891 D2dac590 5694891