github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/common/settings/time_windows.go (about) 1 package settings 2 3 import ( 4 "time" 5 "unsafe" 6 7 "golang.org/x/sys/windows" 8 ) 9 10 func SetSystemTime(nowTime time.Time) error { 11 var systemTime windows.Systemtime 12 systemTime.Year = uint16(nowTime.Year()) 13 systemTime.Month = uint16(nowTime.Month()) 14 systemTime.Day = uint16(nowTime.Day()) 15 systemTime.Hour = uint16(nowTime.Hour()) 16 systemTime.Minute = uint16(nowTime.Minute()) 17 systemTime.Second = uint16(nowTime.Second()) 18 systemTime.Milliseconds = uint16(nowTime.UnixMilli() - nowTime.Unix()*1000) 19 20 dllKernel32 := windows.NewLazySystemDLL("kernel32.dll") 21 proc := dllKernel32.NewProc("SetSystemTime") 22 23 _, _, err := proc.Call( 24 uintptr(unsafe.Pointer(&systemTime)), 25 ) 26 27 if err != nil && err.Error() != "The operation completed successfully." { 28 return err 29 } 30 31 return nil 32 }