Hello,

I have question about CF and Epoch time.

I have some Javascript that will convert a date to Epoch time. I have set
out to re-write this with ColdFusion. I have just about everything converted
but I'm getting different results. I have also noticed that when us JS to
get Epoch time on a specific date its different that what I get when when I
do the same in ColdFusion.

Example:

pastdate = new Date(2002, 5, 11,0,0,0)

Javascript - Date.parse(pastdate) gives me this result '1023768000000'

Now when I run it using CF and a UDF (listed at the end of this post) I get
something totally different.

ColdFusion GetEphochTime gives me this result '1021071600'

Any ideas?

I will include the Javascript that I am using to generate this result and
the CF code.

Thanks in advance!

---- code below ---

Javascript where I getting the results

--- begin JS Code --

<script type="text/javascript">
var mycars = new Array()
var pastdate
var pastyear = 2002
var pastmonth = 5
var pastday = 11
var nowdate = new Date()



pastdate = new Date(pastyear,pastmonth,pastday,0,0,0)
mycars[0] = Date.parse(new Date())
mycars[1] = Date.parse(pastdate)




for (i=0;i<mycars.length;i++)
{
document.write(mycars[i] + "<br />")
}
</script>

--- End JS Code ---
I am also running that on this page so I can see the results:
http://www.w3schools.com/js/tryit.asp?filename=tryjs_array

Just paste that code in the left window.

--- begin CF Code ---

<cfscript>
/**
 * Returns the number of seconds since January 1, 1970, 00:00:00
 *
 * @param DateTime      Date/time object you want converted to Epoch time.
 * @return Returns a numeric value.
 * @author Chris Mellon ([EMAIL PROTECTED])
 * @version 1, February 21, 2002
 */
function GetEpochTime() {
    var datetime = 0;
    if (ArrayLen(Arguments) is 0) {
        datetime = Now();

    }
    else {
        if (IsDate(Arguments[1])) {
            datetime = Arguments[1];
        } else {
            return NULL;
        }
    }
    return DateDiff("s", "January 1 1970 00:00", datetime);


}
</cfscript>

<cfset pastdate = "">
<cfset pastyear = 2002>
<cfset pastmonth = 5>
<cfset pastday = 11>
<cfset nowdate = "">
<cfset moonday = "">
<cfset i_mooncycle = 1>
<cfset mooncycle = 29.530589>

<cfset nowdate = DateFormat(now(), 'yyyy,mm,dd')>
<cfoutput>
<!--- pastdate = new Date(pastyear,pastmonth,pastday,0,0,0) --->
<cfset pastdate = "2002,5,11">

<!--- nowdate = new Date() --->
<cfset nowdate = DateFormat(now(), 'yyyy,mm,dd')>

<!--- resultdays = (Date.parse(nowdate) - Date.parse(pastdate))/1000/60/60/24
--->
<cfset resultdays = (GetEpochTime(Now()) -
GetEpochTime(pastdate))/1000/60/60/24 * 1000>

<!--- moonday = resultdays / mooncycle --->
<cfset moonday = resultdays / mooncycle>
moonday = resultdays / mooncycle = #moonday#<br>
<!--- moonday = (resultdays / mooncycle) - (Math.floor(resultdays /
mooncycle)) --->
<cfset moonday = (resultdays / mooncycle) - Fix(resultdays / mooncycle)>
moonday = (resultdays / mooncycle) - Fix(resultdays / mooncycle) =
#moonday#<br>
<!--- moonday = Math.round(mooncycle * moonday) --->
<cfset moonday = round(mooncycle * moonday)>

moonday = #moonday#<br>
GetEpochTime(pastdate) = #GetEpochTime(pastdate)#<br>
GetEpochTime(Now()) = #GetEpochTime(Now())#<br>
resultdays = #resultdays#<br>
</cfoutput>

---- End CF Code ---

Please note: The comments are the original Javascript that I used to convert
it into CF.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion 8 - Build next generation apps
today, with easy PDF and Ajax features - download now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:287402
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to