2 Star 3 Fork 1

Allen / go-scaffold

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
time.go 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
Allen 提交于 2020-12-18 17:53 . add init struct from env
package util
import (
"time"
)
// NanoGap export
const NanoGap = 1000 * 1000
const timeLayout = "2006-01-02 15:04:05"
// CurrentMilliseconds TL;DR
func CurrentMilliseconds() int64 {
return time.Now().UnixNano() / NanoGap
}
// CurrentTime export
func CurrentTime() string {
return time.Now().Format(timeLayout)
}
// CalcCurrentTimeGap d = duration string
func CalcCurrentTimeGap(d string) (time.Time, error) {
now := time.Now()
gap, err := time.ParseDuration(d)
if err != nil {
return time.Time{}, err
}
return now.Add(gap), nil
}
// BeginningOfMonth export
func BeginningOfMonth(t time.Time) time.Time {
return time.Date(t.Year(), t.Month(), 1, 0, 0, 0, 0, t.Location())
}
// EndOfMonth export
func EndOfMonth(t time.Time) time.Time {
return BeginningOfMonth(t).AddDate(0, 1, 0).Add(-time.Second)
}
// ToDateTimeString TL;DR
func ToDateTimeString(i interface{}, s string) string {
switch v := i.(type) {
case time.Time:
if !v.IsZero() {
return v.Format(s)
}
default:
return ""
}
return ""
}
Go
1
https://gitee.com/zakums06/go-scaffold.git
git@gitee.com:zakums06/go-scaffold.git
zakums06
go-scaffold
go-scaffold
v1.0.14

搜索帮助