time_test.go 692 字节
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())
	timeMarsh(&u1)
}

func timeMarsh(u *User) {
	var u2 = &User{}
	u1Data, _ := json.Marshal(u)
	json.Unmarshal(u1Data, u2)

	fmt.Println("时间:", u2.Age, u2.Age.Local(), u2.AgeZero)
}