Are ColdFusion datetimes stored with a UTC offset?
By @Aidan Whitehall
Yes, ColdFusion date-times are stored with a UTC offset. Charlie's first answer tells you how they are stored. The UTC offset that ColdFusion stores date-times with is implicit, and a default. As ColdFusion is a Java application, its date-times are stored, by default, using the offset of the local timezone of the Java Virtual Machine (JVM) on which ColdFusion is running. That timezone is set in the JVM by means of the flag -Duser.timezone . For example, the following setting ensures that the JVM has UTC timezone:
-Duser.timezone=GMT
If you don't explicitly set the timezone, the JVM will default to using the system timezone of the host operating system on which the JVM is running. This means that the JVM inherits the timezone settings from the environment in which it is executed, rather than defaulting to a specific timezone like UTC. The code samples you have provided suggest that,
you have applied the JVM setting -Duser.timezone=Europe/London, or else,
you have applied no -Duser.timezone setting, which makes the JVM to default to the timezone of your host operating system, which is, presumably, Europe/London.
..., is there any way to access it?
By @Aidan Whitehall
Yes. As you yourself have discovered, ColdFusion stores the current offset as the key utcTotalOffset of the struct getTimeZoneInfo(). In the JVM of your ColdFusion application, the offset is that of the Europe/London timezone.
Now, on to the reason why dateCompare(now, utcNow) produced 0. I don't think this is an error. In fact, I bet that, if you were to run the following code,
dateCompare(now(),current_datetime_in_Los_Angeles_USA)
the result would also be 0, irrespective of where on the planet your ColdFusion server is located.
The reason is simple. I think that, before doing the comparison, ColdFusion casts arguments, where necessary, into date-times having the same offset, namely the offset of the JVM's timezone. That enables ColdFusion to compare like with like.
Long story short: the moral is to explicitly set -Duser.timezone in the JVM on which ColdFusion is running.
... View more