unixtime
This commit is contained in:
parent
74329f91b4
commit
8d6f62699d
@ -1,7 +1,6 @@
|
||||
// A common requirement in programs is getting the number
|
||||
// of seconds, milliseconds, or nanoseconds since the
|
||||
// [Unix epoch](http://en.wikipedia.org/wiki/Unix_time).
|
||||
// Here's how to do it in Go.
|
||||
// Общим требованием в программах является получение
|
||||
// количества секунд, миллисекунд или наносекунд в [Unixtime](http://en.wikipedia.org/wiki/Unix_time).
|
||||
// Вот как это сделать в Go.
|
||||
|
||||
package main
|
||||
|
||||
@ -12,24 +11,24 @@ import (
|
||||
|
||||
func main() {
|
||||
|
||||
// Use `time.Now` with `Unix` or `UnixNano` to get
|
||||
// elapsed time since the Unix epoch in seconds or
|
||||
// nanoseconds, respectively.
|
||||
// Используйте `time.Now` с `Unix` или `UnixNano`,
|
||||
// чтобы получить время, прошедшее с начала эпохи Unix в
|
||||
// секундах или наносекундах соответственно.
|
||||
now := time.Now()
|
||||
secs := now.Unix()
|
||||
nanos := now.UnixNano()
|
||||
fmt.Println(now)
|
||||
|
||||
// Note that there is no `UnixMillis`, so to get the
|
||||
// milliseconds since epoch you'll need to manually
|
||||
// divide from nanoseconds.
|
||||
// Обратите внимание, что `UnixMillis` не существует,
|
||||
// поэтому, чтобы получить миллисекунды с начала эпохи Unix,
|
||||
// вам нужно будет вручную делить наносекунды.
|
||||
millis := nanos / 1000000
|
||||
fmt.Println(secs)
|
||||
fmt.Println(millis)
|
||||
fmt.Println(nanos)
|
||||
|
||||
// You can also convert integer seconds or nanoseconds
|
||||
// since the epoch into the corresponding `time`.
|
||||
// Вы также можете конвертировать целые секунды или наносекунды
|
||||
// Unixtime в соответствующее `время`.
|
||||
fmt.Println(time.Unix(secs, 0))
|
||||
fmt.Println(time.Unix(0, nanos))
|
||||
}
|
||||
|
@ -6,5 +6,5 @@ $ go run epoch.go
|
||||
2012-10-31 16:13:58 +0000 UTC
|
||||
2012-10-31 16:13:58.292387 +0000 UTC
|
||||
|
||||
# Next we'll look at another time-related task: time
|
||||
# parsing and formatting.
|
||||
# Далее мы рассмотрим еще одну задачу, связанную со
|
||||
# временем: разбор и форматирование времени.
|
||||
|
Loading…
x
Reference in New Issue
Block a user