• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JSON Help

Explorer ,
Oct 18, 2010 Oct 18, 2010

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

TOPICS
Advanced techniques

Views

772

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 18, 2010 Oct 18, 2010

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.    

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 18, 2010 Oct 18, 2010

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 18, 2010 Oct 18, 2010

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2010 Oct 19, 2010

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 19, 2010 Oct 19, 2010

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 19, 2010 Oct 19, 2010

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 19, 2010 Oct 19, 2010

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation