How to hide Unix from time to time. Golang time?

I want to hide Unix time (1494505756) in UTC just

import "time"
timeNow := time.Now()

I want to restore timeNow to UTC. How to do it?

+4
source share
1 answer

You can get UTC and unix from the time interface itself.

To convert a unix timestamp to a time object. Use this:

t := time.Unix(1494505756, 0)
fmt.Println(t)

func Unix (sec int64, nsec int64) Time

Unix returns the local time corresponding to the specified Unix time, seconds, and nsec nanoseconds from January 1, 1970 UTC. Indeed, skipping nsec is out of range [0, 999999999]. Not all sec values โ€‹โ€‹have a corresponding time value. One such value is 1 <63.1 (the largest value is int64).

For UTC:

time.Now().UTC()

UTC t , UTC. : https://golang.org/pkg/time/#UTC

Unix:

time.Now().Unix()

Unix t Unix, , 1 1970 UTC. :

+13

Source: https://habr.com/ru/post/1676918/


All Articles