time_test.go
699 字节
package utils
import (
"fmt"
"github.com/linmadan/egglib-go/utils/json"
"testing"
"time"
)
type User struct {
Age time.Time
AgeZero time.Time
AgeZeroFormat string
}
func TestTimeParseInLocal(t *testing.T) {
timeStr := "2022-01-02 1:00:00"
tl, _ := time.ParseInLocation("2006-01-02 15:04:05", timeStr, time.Local)
u1 := User{
Age: tl,
AgeZero: GetZeroTime(tl),
}
u1.AgeZeroFormat = u1.AgeZero.Format("2006-01-02")
fmt.Println(json.MarshalToString(u1), u1.Age.Local())
u2 := User{
Age: tl,
AgeZero: GetZeroTimeWithLocal(tl, time.Local),
}
u2.AgeZeroFormat = u2.AgeZero.Format("2006-01-02")
fmt.Println(json.MarshalToString(u2), u2.Age.Local())
}