<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><title type="text">WeirdLooking.com: Michael Barton's Blog</title><rights>Copyright 2006</rights><author><name>Michael Barton</name><email>palrich@gmail.com</email></author><updated>2012-02-05T08:17:00Z</updated><generator>WeirdLooking.com</generator><logo>http://www.weirdlooking.com/images/feed.png</logo><link rel="alternate" type="text/html" href="http://www.weirdlooking.com/" /><link rel="self" type="application/xml+atom" href="http://www.weirdlooking.com/atom/tag/coldfusion" /><id>http://www.weirdlooking.com/</id><entry><title type="text">mike:1 coldfusion: 0</title><author><name>Michael Barton</name></author><link rel="alternate" type="text/html" href="http://www.weirdlooking.com/blog/mike-1-coldfusion-0" /><id>http://www.weirdlooking.com/blog/mike-1-coldfusion-0</id><published>2005-12-20T01:58:49Z</published><updated>2005-12-20T01:58:49Z</updated><content type="html">&lt;a href=&quot;http://www.tallskinnywhiteguy.com/&quot; style=&quot;position: relative; padding-left: 8px; zoom: 1;&quot;&gt;&lt;span style=&quot;position: absolute; top: -5px; left: 0px; width: 16px; height: 16px; background: URL(http://www.weirdlooking.com/exticon?http%3A%2F%2Fwww.tallskinnywhiteguy.com%2F) no-repeat center center; -moz-opacity: 0.3; opacity: 0.3; filter:alpha(opacity=30);&quot;&gt;&lt;/span&gt;Cole&lt;/a&gt; mentioned that he was trying to parse Unix time stamps from Yahoo&amp;rsquo;s &lt;a href=&quot;http://developer.yahoo.net/traffic/rest/V1/index.html&quot; style=&quot;position: relative; padding-left: 8px; zoom: 1;&quot;&gt;&lt;span style=&quot;position: absolute; top: -5px; left: 0px; width: 16px; height: 16px; background: URL(http://www.weirdlooking.com/exticon?http%3A%2F%2Fdeveloper.yahoo.net%2Ftraffic%2Frest%2FV1%2Findex.html) no-repeat center center; -moz-opacity: 0.3; opacity: 0.3; filter:alpha(opacity=30);&quot;&gt;&lt;/span&gt;traffic web services&lt;/a&gt; to something human-readable.&amp;nbsp; In &lt;a href=&quot;http://www.macromedia.com/software/coldfusion/&quot; style=&quot;position: relative; padding-left: 8px; zoom: 1;&quot;&gt;&lt;span style=&quot;position: absolute; top: -5px; left: 0px; width: 16px; height: 16px; background: URL(http://www.weirdlooking.com/exticon?http%3A%2F%2Fwww.macromedia.com%2Fsoftware%2Fcoldfusion%2F) no-repeat center center; -moz-opacity: 0.3; opacity: 0.3; filter:alpha(opacity=30);&quot;&gt;&lt;/span&gt;ColdFusion&lt;/a&gt;.&amp;nbsp; In case you don&amp;rsquo;t know, CF runs on top of Java and has access to its entire API.&amp;nbsp; &amp;ldquo;Easy&amp;rdquo;, thought I, Java&amp;rsquo;s Date object can deal with milliseconds since epoch, very similar to your Unix time stamps in most regards.&amp;nbsp; ColdFusion&amp;rsquo;s DateFormat function can then be used to translate Date objects into a human-readable string.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;cfset time = 1135038970&amp;gt;&lt;br /&gt;&amp;lt;cfset date = createObject(&amp;quot;java&amp;quot;, &amp;quot;java.util.Date&amp;quot;).init(time * 1000)&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Nope.&amp;nbsp; The constructor takes a long argument and coldfusion&amp;rsquo;s scalars cast to doubles when sent to java.&amp;nbsp; So we turn to ColdFusion&amp;rsquo;s answer, JavaCast.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;cfset date = createObject(&amp;quot;java&amp;quot;, &amp;quot;java.util.Date&amp;quot;).init(JavaCast(&amp;quot;long&amp;quot;, time * 1000))&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This is where it got weird.&amp;nbsp; Coldfusion threw an error that the number was too big to be cast to an int.&amp;nbsp; What?!&amp;nbsp; Why is it casting anything to an int?!&lt;br /&gt;I tried a slight variation:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;cfset date = createObject(&amp;quot;java&amp;quot;, &amp;quot;java.util.Date&amp;quot;).init(JavaCast(&amp;quot;long&amp;quot;, time) * 1000)&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;It cast time to a long alright, but then multiplying it by 1000 casts it back to a double.&amp;nbsp; So I wracked my brain for a way to get this number multiplied by 1000 into a long.&amp;nbsp; Laughing maniacally, I typed it out:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;lt;cfset date = createObject(&amp;quot;java&amp;quot;, &amp;quot;java.util.Date&amp;quot;).init(createObject(&amp;quot;java&amp;quot;, &amp;quot;java.lang.Long&amp;quot;).parseLong(time &amp;amp; &amp;quot;000&amp;quot;))&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You proved a worthy adversary, ColdFusion, but your crane style was no match for my tiger style.&lt;br /&gt;Oh, and there you go, Cole. :D</content><category term="computers and internet" /><category term="coldfusion" /><link rel="comments" type="application/atom+xml" href="http://www.weirdlooking.com/atom/comments/44" /><wfw:commentRss>http://www.weirdlooking.com/atom/comments/44</wfw:commentRss><slash:comments>6</slash:comments></entry></feed>
