TimeFormat

Description

Returns a custom-formatted time value. If no mask is specified, returns a time value using the hh:mm tt format. For international time formatting, see LSTimeFormat.

Category

Date and time functions

Syntax


TimeFormat(time [, mask ]) 

See also

CreateTime, Now, ParseDateTime

Parameters

Parameter
Description
time
A date/time value or string convertible to a time value.
mask
Masking characters that determine the format:
  • h    Hours; no leading zero for single-digit hours (12-hour clock)
  • hh    Hours; leading zero for single-digit hours (12-hour clock)
  • H    Hours; no leading zero for single-digit hours (24-hour clock)
  • HH    Hours; leading zero for single-digit hours (24-hour clock)
  • m    Minutes; no leading zero for single-digit minutes
  • mm    Minutes; a leading zero for single-digit minutes
  • s    Seconds; no leading zero for single-digit seconds
  • ss    Seconds; leading zero for single-digit seconds
  • t    Single-character time marker string, such as A or P
  • tt    Multiple-character time marker string, such as AM or PM

Usage

When passing a date/time value as a string, enclose it in quotes. Otherwise, it is interpreted as a number representation of a date/time object.

Example

<!--- This example shows the types of output with TimeFormat --->

<html>

<head>

<title>

TimeFormat Example

</title>

</head>

<cfset todayDate = #Now()#>



<body>

<H3>TimeFormat Example</H3>



<P>Today's date is <cfoutput>#todayDate#</cfoutput>.



<P>Using Timeformat, we can display the value in different ways:

<cfoutput>

<UL>

  <LI>#TimeFormat(todayDate)#

  <LI>#TimeFormat(todayDate, "hh:mm:ss")#

  <LI>#TimeFormat(todayDate, "hh:mm:sst")#

  <LI>#TimeFormat(todayDate, "hh:mm:sstt")#

  <LI>#TimeFormat(todayDate, "HH:mm:ss")#

</UL>

  

</cfoutput>  



</body>

</html> 





Banner.Novgorod.Ru