Time Format - Coldfusion 9

I am trying to create a timestamp in coldfusion that will include milliseconds.

My problem is that I cannot find the 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 ensures that I have a 9 digit timestamp.

+5
source share
4 answers

Milliseconds with leading zeros?

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

FYI, lhas a maximum of 3 digits. Therefore, I am not sure about your 9-digit limit.

+8
source

Use java SimpleDateFormat !

<cfscript>
   createObject('java','java.text.SimpleDateFormat').init('yyyy-MM-dd HH:mm:ss.SSS Z').format(now());
</cfscript>

Produces 2010-07-19 11:40:14.051 EST

<cfscript>
   createObject('java','java.text.SimpleDateFormat').init('HH:mm:ss.SSS').format(now());
</cfscript>

09:45:12.009 -

+8

, :

- "HH: mm: ssll"...

Just add a third “l” to have the correct number of placeholders:

<cfoutput> 
    <cfset todayDate = #Now()#> 
        <ul> 
            <li>#TimeFormat(todayDate, "HH:mm:sslll")# </li>
        </ul> 
</cfoutput>  
+2
source
    <cfscript>
    function getUniqueID() {
        rightNow = now();
return (dateformat(rightNow,'yyyymmdd') & timeformat(rightNow,"HHmmss") &NumberFormat(TimeFormat(rightNow, "l"),"000") & RandRange(10000, 99999));

    }
    </cfscript>

<cfdump var="#getUniqueID()#">

Just share my code if someone needs to create a unique timestamp for any purpose.

Henry credits for a NumberFormatpiece of code

0
source

All Articles