MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Getting the Date and Time From a Time Server

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120873] Re: Getting the Date and Time From a Time Server
  • From: "Hans Michel" <hmichel at cox.net>
  • Date: Sun, 14 Aug 2011 08:12:22 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201108131047.GAA25453@smc.vnet.net>

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 at videotron.ca] 
Sent: Saturday, August 13, 2011 5:47 AM
To: mathgroup at smc.vnet.net
Subject: [mg120873] 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








  • Prev by Date: Re: ?
  • Next by Date: Re: Map legend
  • Previous by thread: Re: Getting the Date and Time From a Time Server
  • Next by thread: Re: Getting the Date and Time From a Time Server