Search code examples
rubycoldfusioncfml

Coldfusion DateFormat() / TimeFormat() functions to Ruby Time/strftime()


I have the following code on my Coldfusion:

<CFSET ID="TIM#DateFormat(now(), 'YYYYMMDD')##TimeFormat(Now(),'HHmmssl')#">
<cfoutput>ID=#ID#</cfoutput>

That produces (different on time, of course):

ID=TIM20150907072315344

I try to get the same result with ruby but I'm stuck at:

t = Time.new()
ID = t.strftime("%Y%m%d")
puts "ID=TIM#{ID}"

output:

ID=TIM201509

I'm stuck on producing the output of TimeFormat(Now(),'HHmmssl')

Any help?

EDIT: Maybe something like:

t.strftime("%H%M%S%L")

?


Solution

  • You can combine the format of the datetime output in both languages. Your desired string would be:

    ID = Time.­new().strf­time("TIM%­Y%m%d%H%M%­S%L")
    

    in Ruby and...

    <cfset ID = ("TIM" & dateTimeFormat(now(), "yyyymmddHHnnssl"))>
    

    in Coldfusion.

    You can test these simple things online by visiting free services like trytuby.org and trycf.com