package main
import (
"time"
"github.com/PaulMaddox/clock"
)
func main() {
// Get the time
t, err := clock.Get()
if err != nil {
panic(err)
}
// Set the time to 12hrs in the future
t2 := t.Add(12 * time.Hour)
if err := clock.Set(t2); err != nil {
panic(err)
}
}
Package clock is a portable library for setting the system clock.
Supports nanosecond resolution for Linux/Darwin, and second resolution on Windows.
All time values get/set are UTC.
Tested on Linux/Darwin/Windows.
package main
import (
"time"
"github.com/PaulMaddox/clock"
)
func main() {
// Get the time
t, err := clock.Get()
if err != nil {
panic(err)
}
// Set the time
t2 := t.Add(12 * time.Hour)
if err := clock.Set(t2); err != nil {
panic(err)
}
}
Get retrieves the current system time, either via syscall.Gettimeofday on Linux/Darwin
or via kernel32.GetSystemTime() on Windows. It then parses the result into a
standard time.Time struct.