time.js 627 B

12345678910111213141516171819202122232425
  1. var Sntp = require('../lib');
  2. // All options are optional
  3. var options = {
  4. host: 'nist1-sj.ustiming.org', // Defaults to pool.ntp.org
  5. port: 123, // Defaults to 123 (NTP)
  6. resolveReference: true, // Default to false (not resolving)
  7. timeout: 1000 // Defaults to zero (no timeout)
  8. };
  9. // Request server time
  10. Sntp.time(options, function (err, time) {
  11. if (err) {
  12. console.log('Failed: ' + err.message);
  13. process.exit(1);
  14. }
  15. console.log(time);
  16. console.log('Local clock is off by: ' + time.t + ' milliseconds');
  17. process.exit(0);
  18. });