Hi! Thanks for visiting my blog. If you've received any value from my content would you mind supporting my new startup by downloading our browser add-on? It's called PriceBlink and makes online shopping a breeze. You can watch it in action here and download it for Chrome, Firefox, IE, or Safari by going to PriceBlink.com. Thank you and I hope you enjoy!

Long Dates with Flash and ColdFusion

Feb 22

Dealing with dates can be a frustrating task when developing certain applications. After working with Web Services that return dates as long integers, I’ve had no problem handling them with Flash. Take the value 1109129227359 as an example. This is the number of milliseonds that have elapsed since midnight on 1/1/1970. The following code in Flash:

trace(new Date(1109129227359));

will print:

Tue Feb 22 21:27:07 GMT-0600 2005

So it’s fairly simple to handle these long values returned from a Web Service or any other service for that matter. With ColdFusion this is a different story. I never had to deal with long integers in ColdFusion, but didn’t find any functions readily available to use. I tried createdate, createdatetime, parsedate, parsedatetime all with no luck. Finally I tried calling:

#isdate(1109129227359)#

which printed “NO” and left me confused. After some further investigation I decided to try a little math and add the number of seconds that elapsed to 1/1/70. Which led to the following code:

<cfset variables.temp = 1109129227359/1000 />
<cfoutput>
#DateAdd(“s”, variables.temp, “January 1 1970 00:00:00″)#
</cfoutput>

Lo and behold! This worked like a champ but notice how I had to convert from milliseconds to seconds. For some reason CF didn’t support adding milliseconds even though the docs say there’s support for it: click here.

At some point I’d like to dig into this further but you know the saying, if it ain’t broke….