forked from InazumaV/V2bX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynctime.go
39 lines (33 loc) · 839 Bytes
/
synctime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cmd
import (
"fmt"
"github.com/InazumaV/V2bX/common/systime"
"github.com/beevik/ntp"
"github.com/spf13/cobra"
)
var ntpServer string
var commandSyncTime = &cobra.Command{
Use: "synctime",
Short: "Sync time from ntp server",
Args: cobra.NoArgs,
Run: synctimeHandle,
}
func init() {
commandSyncTime.Flags().StringVar(&ntpServer, "server", "time.apple.com", "ntp server")
command.AddCommand(commandSyncTime)
}
func synctimeHandle(_ *cobra.Command, _ []string) {
t, err := ntp.Time(ntpServer)
if err != nil {
fmt.Println(Err("get time from server error: ", err))
fmt.Println(Err("同步时间失败"))
return
}
err = systime.SetSystemTime(t)
if err != nil {
fmt.Println(Err("set system time error: ", err))
fmt.Println(Err("同步时间失败"))
return
}
fmt.Println(Ok("同步时间成功"))
}