CFLib.org – Common Function Library Project

getNISTTime([timeServer])

Last updated December 7, 2005

author

Ben Forta

Version: 1 | Requires: CF6 | Library: UtilityLib

Description:
Obtains current time data from NIST Internet Time Service servers.

Return Values:
Returns a structure.

Example:

<cfdump var="#getNISTTime()#">

Parameters:

Name Description Required
timeServer Time server. Defaults to 192.43.244.18. No

Full UDF Source:

<!---
 Obtains current time data from NIST Internet Time Service servers.
 
 @param timeServer 	 Time server. Defaults to 192.43.244.18. (Optional)
 @return Returns a structure. 
 @author Ben Forta (ben@forta.com) 
 @version 1, December 7, 2005 
--->
<cffunction name="GetNISTTime" returntype="struct" output="false">
	<cfargument name="timeServer" type="string" default="192.43.244.18" required="false">
	<cfset var result=StructNew()>

	<!--- Try/catch block --->
	<cftry>

      <!--- Try get time data --->
      <cfhttp url="http://#arguments.timeServer#:13/" />
      <!--- Save raw data --->
      <cfset result.raw = CFHTTP.FileContent>
      <!--- Extract Julian date --->
      <cfset result.julian=ListGetAt(result.raw, 1, " ")>
      <!--- Extract current date and time --->
      <cfset result.now=ParseDateTime(ListGetAt(result.raw, 2, " ")
                              & " "
                              & ListGetAt(result.raw, 3, " "))>
      <!--- Extract daylight savings time flag --->
      <cfset result.dst=IIf(ListGetAt(result.raw, 4, " ") IS 0,
                        FALSE, TRUE)>
      <!--- Extract leap month flag --->
      <cfset result.leapmonth=IIf(ListGetAt(result.raw, 5, " ") IS 0,
                           FALSE, TRUE)>
      <!--- Extract health flag --->
      <cfset result.healthy=IIf(ListGetAt(result.raw, 6, " ") IS 0,
                           FALSE, TRUE)>
      <!--- Extract advance milliseconds --->
      <cfset result.msadv=ListGetAt(result.raw, 7, " ")>
      <!--- Success --->
      <cfset result.success=TRUE>

      <!--- Catch any errors --->
      <cfcatch type="any">
         <cfset result.success=FALSE>
      </cfcatch>

	</cftry>

	<cfreturn result>

</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson