Skip to content

bt51/ntpclient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ntpclient


GoDoc

ntpclient is a simple NTP client for go. It supports NTP version 4 and SNTP. Note that this client currently does not take network delay into account. This means the time that is received will not be accurate to the nanosecond.

Installation

Make sure you have a working Go environment (go 1.1 is required). See the install instructions.

To install ntpclient, run:

$ go get github.com/bt51/ntpclient

Usage

Getting the current time from an ntp server is simple.

package main

import (
    "fmt"

    "github.com/bt51/ntpclient"
)

func main() {
    t, err := ntpclient.GetNetworkTime("0.pool.ntp.org", 123)
    if err != nil {
        fmt.Println(err)    
    }
    fmt.Println(t)
}

If the current time was returned from the ntp server, it will be converted to a time.Time type and returned. Note that the time will be in UTC so if you want it to be local, you will have to change the correct timezone.

License

MIT

About

Go (golang) ntp client.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages