fox/xtime/parser.go

42 lines
1.1 KiB
Go

package xtime
import (
"github.com/golang-module/carbon/v2"
)
// 解析系统时区输出的字符串、时间戳,转为偏移时区
// 注意如果你的时间戳和字符串已经是偏移时区输出的,就不应使用下列解析函数!
func Parse(value string, offsets ...int) (c *carbon.Carbon) {
c = carbon.Parse(value)
c = set(c, offsets...)
return c
}
//goland:noinspection GoUnusedExportedFunction
func FromUnix(sec int64, offsets ...int) *carbon.Carbon {
c := carbon.CreateFromTimestamp(sec)
c = set(c, offsets...)
return c
}
func FromUnixMilli(msec int64, offsets ...int) *carbon.Carbon {
c := carbon.CreateFromTimestampMilli(msec)
c = set(c, offsets...)
return c
}
//goland:noinspection GoUnusedExportedFunction
func FromUnixMicro(msec int64, offsets ...int) *carbon.Carbon {
c := carbon.CreateFromTimestampMicro(msec)
c = set(c, offsets...)
return c
}
//goland:noinspection GoUnusedExportedFunction
func FromUnixNano(msec int64, offsets ...int) *carbon.Carbon {
c := carbon.CreateFromTimestampNano(msec)
c = set(c, offsets...)
return c
}