In ColdFusion, when you create a true date/time object, it is represented, behind the scenes, as a Java Date object. Now, this is an undocumented feature of ColdFusion, so everything else in this entry should be viewed through this lens. Over the weekend, while working with UTC date/times, I noticed a change in behavior of the date/time objects between ColdFusion 9 and ColdFusion 10.
To demonstrate, take a look at this code which attempts to get the UTC milliseconds since January 1, 1970:
<!--- Get the local time and the UTC equivalen. ---> <cfset localDate = now() /> <cfset utcDate = dateConvert( "local2utc", localDate ) /> <!--- Output the millseconds since the epoch. ---> <cfoutput> Server: #server.coldfusion.productVersion#<br /> <br /> L: #localDate.getTime()#<br /> U: #utcDate.getTime()#<br /> </cfoutput>
This takes the local date and converts it to the equivalent UTC date. It then tries to get the milliseconds from 1970 for both dates. When this is run in ColdFusion 10, we get the following output:
As you can see, the getTime() method calls return the same value in both cases.
When we run this in ColdFusion 9, however, we get the following output:
As you can see here, the getTime() method calls return two different values.
I don't have the best grasp on UTC time; nor do I feel terribly comfortable working with timezones. That said, from a philosophical standpoint, I would expect getTime() to return the same value for both local and UTC dates. Since the milliseconds since epoch is the same all over the world (from my understanding), then converting from one timezone to another (or from local to UTC) should have no bearing on the milliseconds since 1970.
That said, it appears like ColdFusion 10 has the correct behavior. But, this post was more to point out the difference, and less so to speculate as to which case is correct. Remember, this is an undocumented feature anyway. Also, to complicate the matter, a UTC bug has already been submitted for ColdFusion 10, which may or may not be related to this behavior.
Want to use code from this post? Check out the license.