Time Format - Coldfusion 9

Geo picture Geo · Jul 18, 2012 · Viewed 9.9k times · Source

I am trying to create a time stamp in coldfusion that would include milliseconds.

My issue is that I cannot find a code anywhere that would allow me to keep the format consistent by controlling leading zeros.

This is my format:

<cfoutput> 
<cfset todayDate = #Now()#> 
<ul> 
    <li>#TimeFormat(todayDate, "HH:mm:ssl")# </li>
</ul> 
</cfoutput>  

I just need something like "HH:mm:ssll" or some other method that will ensure that I would have a 9 digit timestamp at all times.

Answer

Henry picture Henry · Jul 19, 2012

Milliseconds with leading zeros?

<li>
  #TimeFormat(todayDate, "HH:mm:ss")##NumberFormat(TimeFormat(todayDate, "l"),"000")#
</li>

FYI, l has maximum of 3 digits. So I'm not sure about your 9-digits limit.