Copy link to clipboard
Copied
I'm using JQuery's Flot plug-in and I need to pass JSON datetime values in the form of timestamps.
In looking at their examples they use timestamp values such as 1096581600000, 1107212400000, -357699600000, etc.
When I run a query and do #SerializeJSON(dtVal)# I get "October, 18 2009 17:16:48", which isn't a JS friendly value.
I thought the issue had to do with converting it to UTC, so I tried this: #evaluate(SerializeJSON(dtMonthYear)*1000)#
But that generates this error:
The value "October, 18 2009 17:18:37" cannot be converted to a number
I'm out of ideas.
Can someone shed some light?
TIA
Copy link to clipboard
Copied
What do these timestamp values represent? They look like they might be the number of second of milliseconds between the selected date and some constant date.
Copy link to clipboard
Copied
Dan,
Per http://people.iola.dk/olau/flot/API.txt
The time series support in Flot is based on Javascript timestamps, i.e. everywhere a time value is expected or handed over, a Javascript timestamp number is used. This is a number, not a Date object. A Javascript timestamp is the number of milliseconds since January 1, 1970 00:00:00 UTC. This is almost the same as Unix timestamps, except it's in milliseconds, so remember to multiply by 1000!
Thanks
Copy link to clipboard
Copied
You could use this UDF to get the # of seconds since epoch (then
multiply by 1k): http://www.cflib.org/udf/GetEpochTime
Copy link to clipboard
Copied
This #evaluate(GetEpochTime(createDate(2009,10,31))*1000)# returns this: 1.2569436E+012
This #GetEpochTime(createDate(2009,10,31))# returns this: 1256943600
The second one looks right, but it's not being multiplied by 1000, which needs to happen?
Also, since this app will run on CF 6.1 I was planning on using CFJSON (http://www.epiphantastic.com/cfjson/index.php), since I can't use SerializeJSON()
Has anyone used their CFC?
Thanks
Copy link to clipboard
Copied
THe number may be too big for CF... try getting rid of the evaluate
though and just output it.
And I've used that cfjson CFC before. It works well.
Copy link to clipboard
Copied
I got rid of evaluate() but I'm still getting 1.2569436E+012
Below is the code I'm using:
<cfset EpochDateTimeArray = ArrayNew(1)>
<cfoutput query="getData">
<cfset EpochDateTimeArray[getData.currentRow] = GetEpochTime(createDate(2009,10,31))*1000>
</cfoutput>
<cfscript>
QueryAddColumn(getData, "EpochDateTime", EpochDateTimeArray);
</cfscript>
I was going to use CFJSON to encode the "EpochDateTime" column and pass it to the Flot function.
I still have to figure out how to just pass EpochDateTime (instead of the entire dataset).
Does this seem right?
Thanks again
Copy link to clipboard
Copied
1.2569436E+012 is simply another way of displaying a really big number. Use numberformat to make it more readable. You should be able to pass either the number or the string to your javascript function.