package main import ( "fmt" "time" ) func main() { now := time.Now() fmt.Println("Current time:", now) }
package main import ( "fmt" "time" ) func main() { dateStr := "2006-01-02" date, err := time.Parse(dateStr, "2021-05-07") if err != nil { fmt.Println("Error:", err) } else { fmt.Println("Parsed date:", date) } }
package main import ( "fmt" "time" ) func main() { date := time.Date(2021, 5, 7, 0, 0, 0, 0, time.UTC) newDate := date.Add(time.Hour * 24) fmt.Println("Original date:", date) fmt.Println("New date:", newDate) }This code creates a `time.Time` object representing May 7th, 2021 and then adds 24 hours to it using the `time.Add()` function. The original and new dates are printed to the console. In all of these examples, the `time` package library is used.