f



Getting the Date and Time From a Time Server

Hello everyone,

Is there a way to use the Import function to grab the current date and time from a time server on the Internet?

Regards,

Gregory



0
8/13/2011 10:49:28 AM
comp.soft-sys.math.mathematica 28821 articles. 0 followers. Follow

2 Replies
576 Views

Similar Articles

[PageSpeed] 36

Maybe you could run the "ntpdate" program external and retreive the
time offset between your computer clock and the time server.
(in the following example, the time server is only good in canada)

Run["ntpdate -q time.chu.nrc.ca >/tmp/toto"]
res=Import["/tmp/toto", "Table","FieldSeparators" -> {" ", ","}]
offset=res[[1,6]]   (* not very portable... :-( *)

Now you can use the internal Mathematica clock and add the offset to
get the correct time.

DateList[AbsoluteTime[]+offset]


0
roys3d (2)
8/15/2011 12:24:02 AM
>> Run["ntpdate -q time.chu.nrc.ca >/tmp/toto"]

An alternative to this approach that I have had come luck with is:

ReadList["!ntpdate -q time.chu.nrc.ca", Record]

This returns a string that is the sum of the program output.  It is analogous to a pipe back into a Mathematica String.  You may need to specify a path.  The nice part is the lack of a generated file.


Paul McHale  |  Electrical Engineer, Energetics Systems  |  Excelitas Technologies Corp.

Phone:   +1 937.865.3004   |   Fax:  +1 937.865.5170   |   Mobile:   +1 937.371.2828
1100 Vanguard Blvd, Miamisburg, Ohio 45342-0312 USA
Paul.McHale@Excelitas.com
www.excelitas.com



Please consider the environment before printing this e-mail.
This email message and any attachments are confidential and proprietary to Excelitas Technologies Corp. If you are not the intended recipient of this message, please inform the sender by replying to this email or sending a message to the sender and destroy the message and any attachments.
Thank you

-----Original Message-----
From: S=E9bastien Roy [mailto:roys3d@gmail.com]
Sent: Sunday, August 14, 2011 8:20 PM
Subject: Re: Getting the Date and Time From a Time Server

Maybe you could run the "ntpdate" program external and retreive the
time offset between your computer clock and the time server.
(in the following example, the time server is only good in canada)

Run["ntpdate -q time.chu.nrc.ca >/tmp/toto"]
res=Import["/tmp/toto", "Table","FieldSeparators" -> {" ", ","}]
offset=res[[1,6]]   (* not very portable... :-( *)

Now you can use the internal Mathematica clock and add the offset to
get the correct time.

DateList[AbsoluteTime[]+offset]



0
8/19/2011 10:35:13 AM
Reply: