This commit is contained in:
Sangeeth Sudheer 2024-05-02 13:26:46 +05:30
parent b1fe04a282
commit b6550b9032
Signed by: x
GPG Key ID: F6D06ECE734C57D1
2 changed files with 57 additions and 2 deletions

View File

@ -27,7 +27,8 @@ package main
// import "git.sangeeth.dev/gobyexample/templates"
// import "git.sangeeth.dev/gobyexample/regex"
// import "git.sangeeth.dev/gobyexample/json"
import "git.sangeeth.dev/gobyexample/xml"
// import "git.sangeeth.dev/gobyexample/xml"
import "git.sangeeth.dev/gobyexample/time"
func main() {
// runes.Runes()
@ -57,5 +58,6 @@ func main() {
// templates.Templates()
// regex.Regex()
// json.Json()
xml.Xml()
// xml.Xml()
time.Time()
}

53
time/time.go Normal file
View File

@ -0,0 +1,53 @@
package time
import (
"fmt"
"time"
)
var f = fmt.Println
func epoch() {
now := time.Now().UTC()
f("Epoch seconds:", now.Unix())
f("Epoch milli:", now.UnixMilli())
f("Epoch nano:", now.UnixNano())
f("Custom time from epoch:", time.Unix(now.Unix(), 0))
f("Custom time from epoch:", time.Unix(0, now.UnixNano()))
}
func Time() {
now := time.Now().UTC()
f(now)
xmasTime := time.Date(2023, 12, 25, 9, 0, 0, 0, time.UTC)
f("XMAS =>", xmasTime)
f("Year:", xmasTime.Year())
f("Month:", xmasTime.Month())
f("Day:", xmasTime.Day())
f("Hour:", xmasTime.Hour())
f("Minute:", xmasTime.Minute())
f("Second:", xmasTime.Second())
f("Nanosecond:", xmasTime.Nanosecond())
f("Weekday:", xmasTime.Weekday())
f("Is Xmas before now?", xmasTime.Before(now))
f("Is Xmas after now?", xmasTime.After(now))
f("Is Xmas same as now?", xmasTime.Equal(now))
diff := now.Sub(xmasTime)
f(diff)
f(diff.Hours())
f(diff.Minutes())
f(diff.Seconds())
f(diff.Nanoseconds())
f(xmasTime.Add(diff))
f(now.Add(-diff))
epoch()
}