32 lines
652 B
Go
32 lines
652 B
Go
package timeutil
|
|
|
|
import "time"
|
|
|
|
const (
|
|
APITimeLayout = "2006-01-02T15:04:05-07:00"
|
|
OrderNoLayout = "20060102150405"
|
|
)
|
|
|
|
var businessLocation = time.FixedZone("CST", 8*60*60)
|
|
|
|
func Location() *time.Location {
|
|
return businessLocation
|
|
}
|
|
|
|
func Now() time.Time {
|
|
return time.Now().In(businessLocation)
|
|
}
|
|
|
|
func FormatAPITime(value time.Time) string {
|
|
if value.IsZero() {
|
|
return ""
|
|
}
|
|
return value.In(businessLocation).Truncate(time.Second).Format(APITimeLayout)
|
|
}
|
|
|
|
func StartOfDay(value time.Time) time.Time {
|
|
local := value.In(businessLocation)
|
|
year, month, day := local.Date()
|
|
return time.Date(year, month, day, 0, 0, 0, 0, businessLocation)
|
|
}
|