Time transformation

timeLayout := "2006-01-02 15:04:05"

1. Get the server time

fmt.Println(time.Now().Format(timeLayout))

2. Get the UTC time

fmt.Println(time.Now().UTC().Format(timeLayout))

3. Convert server time to UTC time

Timestr := "2021-05-18 12:00:00" // Timestr := "2021-05-18 12:00:00" // Timestr := "2021-05-18 12:00:00" Note that Local localTime, _ := time. parseInLocation (timeLayout, timeStr, timeStr) Location) fmt.println (localtime.utc ().format (timeLayout)) // To UTC time

Note: Note the timeStr value, which we treat as the server time at this point, so time.loadLocation (“Local”) uses Local

4. Convert UTC time to server time

TimeStr := "2021-05-18 12:00:00" // TimeStr := "2021-05-18 12:00:00" // TimeStr := "2021-05-18 12:00:00" // TimeStr := "2021-05-18 12:00:00" // TimeStr := "2021-05-18 12:00:00" // TimeStr := "2021-05-18 12:00:00" Note that using UTC LocalTime, _ := Time.ParseInLocation(timeLayout, timeStr, Location) fmt.println (localtime.local ().format (timeLayout)) // Convert to Local server time

Note: Note the timeStr value, which we treat as UTC time at this point, so time.loadLocation (“UTC”) uses Local

A little time

timeLayout := "2006-01-02 15:04:05"
Timestr := "2021-05-17 11:00:00" // Timestr := "2021-05-17 11:00:00" // Timestr := "2021-05-17 11:00:00" Note that Local localTime, _ := time. parseInLocation (timeLayout, timeStr, timeStr) Location) fmt.println (localtime.utc ().format (timeLayout)) // CompareTimeStr := "2021-05-17 02:00:00" // To UTC time Location, _ = time. loadLocation ("UTC") // timeStr = Beijing time, Note that using UTC compareTime, _ := time. parseInLocation (timeLayout, compareTimeStr, Location) fmt.println (compareTime.local ().format (timeLayout)) // Conversion to server time FMT. Println (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ") FMT. Println (compareTime. Before (localTime)) / / Before will be unified time reference point FMT.Println(comparetime. After(localTime)) // After will unify the time reference point

When the time zone is changed to golang time. time, the time zone is changed to golang time. time, the time zone is changed to golang time. time.