All Projects → beevik → Ntp

beevik / Ntp

Licence: bsd-2-clause
a simple ntp client package for go

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to Ntp

clock
High-resolution clock functions: monotonic, realtime, cputime.
Stars: ✭ 52 (-84.66%)
Mutual labels:  time
Timy
Minimalist measurement of python code time
Stars: ✭ 273 (-19.47%)
Mutual labels:  time
M
Stars: ✭ 313 (-7.67%)
Mutual labels:  time
edtf.js
Extended Date Time Format (ISO 8601-2 / EDTF) Parser for JavaScript
Stars: ✭ 44 (-87.02%)
Mutual labels:  time
Javascript Time Ago
International highly customizable relative date/time formatting
Stars: ✭ 263 (-22.42%)
Mutual labels:  time
Awesome Falsehood
😱 Falsehoods Programmers Believe in
Stars: ✭ 16,614 (+4800.88%)
Mutual labels:  time
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-89.38%)
Mutual labels:  time
Tqdm
A Fast, Extensible Progress Bar for Python and CLI
Stars: ✭ 20,632 (+5986.14%)
Mutual labels:  time
Md Date Time Picker
An implementation of Material Design Picker components in vanilla CSS, JS, and HTML
Stars: ✭ 272 (-19.76%)
Mutual labels:  time
Timestamp
⏰ A better macOS menu bar clock.
Stars: ✭ 296 (-12.68%)
Mutual labels:  time
NTP
NTP library for Arduino framework
Stars: ✭ 20 (-94.1%)
Mutual labels:  time
react-ago-component
A component for React that renders the approximate time ago in words from a specific past date using an HTML5 time element.
Stars: ✭ 25 (-92.63%)
Mutual labels:  time
Timecop
A gem providing "time travel", "time freezing", and "time acceleration" capabilities, making it simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.
Stars: ✭ 3,110 (+817.4%)
Mutual labels:  time
date-php
这是一个Javascript模仿PHP日期时间格式化函数,使用方法和PHP非常类似,有丰富的模板字符,并在原来的基础上增加了一些模板字符。 This is a date function that implement PHP in Javascript. It is very similar to PHP, has rich template characters, and enhances some template characters on the basis of the original.
Stars: ✭ 24 (-92.92%)
Mutual labels:  time
Oycountdownmanager
在cell中使用倒计时的处理方法, 全局使用一个NSTimer对象, 支持单列表.多列表.多页面.分页列表使用
Stars: ✭ 317 (-6.49%)
Mutual labels:  time
date4j
Lightweight alternative to Java's built-in date-time classes. Android-friendly. Compiles under JDK 1.5.
Stars: ✭ 36 (-89.38%)
Mutual labels:  time
Now
Now is a time toolkit for golang
Stars: ✭ 3,506 (+934.22%)
Mutual labels:  time
Time
Simple time handling in Rust
Stars: ✭ 334 (-1.47%)
Mutual labels:  time
Maya
Datetimes for Humans™
Stars: ✭ 3,298 (+872.86%)
Mutual labels:  time
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (-13.27%)
Mutual labels:  time

Build Status GoDoc

ntp

The ntp package is an implementation of a Simple NTP (SNTP) client based on RFC5905. It allows you to connect to a remote NTP server and request information about the current time.

Querying the current time

If all you care about is the current time according to a remote NTP server, simply use the Time function:

time, err := ntp.Time("0.beevik-ntp.pool.ntp.org")

Querying time metadata

To obtain the current time as well as some additional metadata about the time, use the Query function:

response, err := ntp.Query("0.beevik-ntp.pool.ntp.org")
time := time.Now().Add(response.ClockOffset)

Alternatively, use the QueryWithOptions function if you want to change the default behavior used by the Query function:

options := ntp.QueryOptions{ Timeout: 30*time.Second, TTL: 5 }
response, err := ntp.QueryWithOptions("0.beevik-ntp.pool.ntp.org", options)
time := time.Now().Add(response.ClockOffset)

The Response structure returned by Query includes the following information:

  • Time: The time the server transmitted its response, according to its own clock.
  • ClockOffset: The estimated offset of the local system clock relative to the server's clock. For a more accurate time reading, you may add this offset to any subsequent system clock reading.
  • RTT: An estimate of the round-trip-time delay between the client and the server.
  • Precision: The precision of the server's clock reading.
  • Stratum: The server's stratum, which indicates the number of hops from the server to the reference clock. A stratum 1 server is directly attached to the reference clock. If the stratum is zero, the server has responded with the "kiss of death".
  • ReferenceID: A unique identifier for the consulted reference clock.
  • ReferenceTime: The time at which the server last updated its local clock setting.
  • RootDelay: The server's aggregate round-trip-time delay to the stratum 1 server.
  • RootDispersion: The server's estimated maximum measurement error relative to the reference clock.
  • RootDistance: An estimate of the root synchronization distance between the client and the stratum 1 server.
  • Leap: The leap second indicator, indicating whether a second should be added to or removed from the current month's last minute.
  • MinError: A lower bound on the clock error between the client and the server.
  • KissCode: A 4-character string describing the reason for a "kiss of death" response (stratum=0).
  • Poll: The maximum polling interval between successive messages to the server.

The Response structure's Validate method performs additional sanity checks to determine whether the response is suitable for time synchronization purposes.

err := response.Validate()
if err == nil {
    // response data is suitable for synchronization purposes
}

Using the NTP pool

The NTP pool is a shared resource used by people all over the world. To prevent it from becoming overloaded, please avoid querying the standard pool.ntp.org zone names in your applications. Instead, consider requesting your own vendor zone or joining the pool.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].