mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
fix: coding style and file format for all example.
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var week time.Duration
|
||||
|
||||
func main() {
|
||||
t := time.Now()
|
||||
fmt.Println(t) // Wed Dec 21 09:52:14 +0100 RST 2011
|
||||
fmt.Printf("%02d.%02d.%4d\n", t.Day(), t.Month(), t.Year()) // 21.12.2011
|
||||
t = time.Now().UTC()
|
||||
fmt.Println(t) // Wed Dec 21 08:52:14 +0000 UTC 2011
|
||||
fmt.Println(time.Now()) // Wed Dec 21 09:52:14 +0100 RST 2011
|
||||
// calculating times:
|
||||
week = 60 * 60 * 24 * 7 * 1e9 // must be in nanosec
|
||||
week_from_now := t.Add(week)
|
||||
fmt.Println(week_from_now) // Wed Dec 28 08:52:14 +0000 UTC 2011
|
||||
// formatting times:
|
||||
fmt.Println(t.Format(time.RFC822)) // 21 Dec 11 0852 UTC
|
||||
fmt.Println(t.Format(time.ANSIC)) // Wed Dec 21 08:56:34 2011
|
||||
fmt.Println(t.Format("02 Jan 2006 15:04")) // 21 Dec 2011 08:52
|
||||
s := t.Format("20060102")
|
||||
fmt.Println(t, "=>", s) // Wed Dec 21 08:52:14 +0000 UTC 2011 => 20111221
|
||||
}
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var week time.Duration
|
||||
|
||||
func main() {
|
||||
t := time.Now()
|
||||
fmt.Println(t) // Wed Dec 21 09:52:14 +0100 RST 2011
|
||||
fmt.Printf("%02d.%02d.%4d\n", t.Day(), t.Month(), t.Year()) // 21.12.2011
|
||||
t = time.Now().UTC()
|
||||
fmt.Println(t) // Wed Dec 21 08:52:14 +0000 UTC 2011
|
||||
fmt.Println(time.Now()) // Wed Dec 21 09:52:14 +0100 RST 2011
|
||||
// calculating times:
|
||||
week = 60 * 60 * 24 * 7 * 1e9 // must be in nanosec
|
||||
week_from_now := t.Add(week)
|
||||
fmt.Println(week_from_now) // Wed Dec 28 08:52:14 +0000 UTC 2011
|
||||
// formatting times:
|
||||
fmt.Println(t.Format(time.RFC822)) // 21 Dec 11 0852 UTC
|
||||
fmt.Println(t.Format(time.ANSIC)) // Wed Dec 21 08:56:34 2011
|
||||
fmt.Println(t.Format("02 Jan 2006 15:04")) // 21 Dec 2011 08:52
|
||||
s := t.Format("20060102")
|
||||
fmt.Println(t, "=>", s) // Wed Dec 21 08:52:14 +0000 UTC 2011 => 20111221
|
||||
}
|
||||
|
Reference in New Issue
Block a user