Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4381

Re: Getting the Date and Time From a Time Server

From "Hans Michel" <hmichel@cox.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Getting the Date and Time From a Time Server
Date 2011-08-14 12:14 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j28e6a$39s$1@smc.vnet.net> (permalink)
References <201108131047.GAA25453@smc.vnet.net>

Show all headers | View raw


Using Mathematica Version 7

$Version

"7.0 for Microsoft Windows (32-bit) (February 18, 2009)"

Import["http://time.nist.gov:13/"]
With port numbers fails.

Try the following trick: 

In[1]:= getNISTTime[] := 
  Module[{NISTTimeXML, result}, 
   NISTTimeXML = 
    ImportString[
     "<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE NISTTime \
[<!ENTITY datetime SYSTEM
          'http://time.nist.gov:13/'><!ELEMENT NISTTime \
(#PCDATA)>]><NISTTime>&datetime;</NISTTime>", "XML"];
   result = 
    First[Cases[NISTTimeXML, XMLElement["NISTTime", {}, ___], 
        Infinity]][[3]][[1]];
   result];


In[2]:= getNISTTime[]

Out[2]= "55786 11-08-13 18:24:53 50 0 0 441.7 UTC(NIST) *"

Got to this site to get how to decode the format
http://www.nist.gov/pml/div688/grp40/its.cfm

As for Modified Julian Date I and others have posted some solutions to that
please search newsgroup. Go here for definition
(http://scienceworld.wolfram.com/astronomy/ModifiedJulianDate.html)

One can change to different time servers as needed.
(http://tf.nist.gov/tf-cgi/servers.cgi) change the URI (URL) in the ENTITY
definition.

This trick involves using the built-in XML functionality. The XML string has
a defined and external/system entity whose resource requires the parser to
go get and place in the full content of the defined entity in the where it
is called in content of the XML document. 

"AllowUnrecognizedEntities" in XML attributes in Mathematica is defaulted to
True. If entities can not be fetched on your system you may need to adjust
this attribute in Mathematica. There may also be firewall issues.

Please note that telnet time.nist.gov 13 should also work.

This is pasted using plaintext just in case the breaks get messed up by
reader or email:

In[1]:=
getNISTTime[]:=Module[{NISTTimeXML,result},NISTTimeXML=ImportString["<?xml
version='1.0' encoding='UTF-8'?><!DOCTYPE NISTTime [<!ENTITY datetime SYSTEM
     'http://time.nist.gov:13/'><!ELEMENT NISTTime
(#PCDATA)>]><NISTTime>&datetime;</NISTTime>","XML"];
result=First[Cases[NISTTimeXML,XMLElement["NISTTime",{},___],Infinity]][[3]]
[[1]];
result];

In[2]:= getNISTTime[]
Out[2]= 55786 11-08-13 18:24:53 50 0 0 441.7 UTC(NIST) *

Hans

-----Original Message-----
From: Gregory Lypny [mailto:gregory.lypny@videotron.ca] 
Sent: Saturday, August 13, 2011 5:47 AM
Subject: 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




Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Getting the Date and Time From a Time Server "Hans Michel" <hmichel@cox.net> - 2011-08-14 12:14 +0000

csiph-web