время

This commit is contained in:
badkaktus 2019-10-09 22:23:43 +03:00
parent bee3c75b76
commit 74329f91b4
3 changed files with 19 additions and 22 deletions

View File

@ -47,7 +47,7 @@ Defer
Регулярные выражения (Regular Expressions) Регулярные выражения (Regular Expressions)
JSON JSON
XML XML
Time Время (Time)
Epoch Epoch
Time Formatting / Parsing Time Formatting / Parsing
Random Numbers Random Numbers

View File

@ -1,5 +1,5 @@
// Go offers extensive support for times and durations; // Go предлагает обширную поддержку для времени и
// here are some examples. // продолжительности; вот несколько примеров.
package main package main
@ -11,19 +11,18 @@ import (
func main() { func main() {
p := fmt.Println p := fmt.Println
// We'll start by getting the current time. // Начнем с получения текущего времени
now := time.Now() now := time.Now()
p(now) p(now)
// You can build a `time` struct by providing the // Вы можете построить структуру `time`, указав год,
// year, month, day, etc. Times are always associated // месяц, день и т.д. Время всегда связано с `местоположением`,
// with a `Location`, i.e. time zone. // т.е. часовым поясом.
then := time.Date( then := time.Date(
2009, 11, 17, 20, 34, 58, 651387237, time.UTC) 2009, 11, 17, 20, 34, 58, 651387237, time.UTC)
p(then) p(then)
// You can extract the various components of the time // Вы можете извлечь различные компоненты значения времени.
// value as expected.
p(then.Year()) p(then.Year())
p(then.Month()) p(then.Month())
p(then.Day()) p(then.Day())
@ -33,31 +32,30 @@ func main() {
p(then.Nanosecond()) p(then.Nanosecond())
p(then.Location()) p(then.Location())
// The Monday-Sunday `Weekday` is also available. // Получения дня недели доступно через метод `Weekday`.
p(then.Weekday()) p(then.Weekday())
// These methods compare two times, testing if the // Эти методы сравниваются два раза, проверяя,
// first occurs before, after, or at the same time // происходит ли первый случай до, после или
// as the second, respectively. // одновременно со вторым, соответственно.
p(then.Before(now)) p(then.Before(now))
p(then.After(now)) p(then.After(now))
p(then.Equal(now)) p(then.Equal(now))
// The `Sub` methods returns a `Duration` representing // Метод `Sub` возвращает `Duration`, интервал между
// the interval between two times. // двумя временами.
diff := now.Sub(then) diff := now.Sub(then)
p(diff) p(diff)
// We can compute the length of the duration in // Мы можем вычислить продолжительность.
// various units.
p(diff.Hours()) p(diff.Hours())
p(diff.Minutes()) p(diff.Minutes())
p(diff.Seconds()) p(diff.Seconds())
p(diff.Nanoseconds()) p(diff.Nanoseconds())
// You can use `Add` to advance a time by a given // Вы можете использовать `Add`, чтобы продвинуть
// duration, or with a `-` to move backwards by a // время на заданную продолжительность, или с `-`,
// duration. // чтобы переместиться назад.
p(then.Add(diff)) p(then.Add(diff))
p(then.Add(-diff)) p(then.Add(-diff))
} }

View File

@ -21,5 +21,4 @@ false
2012-10-31 15:50:13.793654 +0000 UTC 2012-10-31 15:50:13.793654 +0000 UTC
2006-12-05 01:19:43.509120474 +0000 UTC 2006-12-05 01:19:43.509120474 +0000 UTC
# Next we'll look at the related idea of time relative to # Далее мы рассмотрим время относительно эпохи Unix.
# the Unix epoch.