Formats date and time values using date and time formatting conventions.
A string representing a formatted date and time value.
ColdFusion (2016 release) Update 3: SimpleDateFormat's mask a is no longer followed. Use the masks t and tt to return the character string A/P or AM/PM respectively.
ColdFusion 10: Added this function.
dateTimeFormat (date) dateTimeFormat (date [, mask]) dateTimeFormat (date [, mask, timeZone])
Parameter |
Description |
|---|---|
date |
Required. A date/time object, in the range 100 AD-9999 AD. |
mask |
Optional. Characters that show how ColdFusion displays a date:
The following masks tell how to format the full date and time and cannot be combined with other masks:
The function also follows Java date time mask, except for mask a. For more information, refer to Date and Time Patterns topic in SimpleDateFormat Java API page. JDK7 and JDK8 introduces the masks w, ww , W, and WW. |
timeZone |
The time-zone information. You can specify in either of the following formats:
|
<cfscript>
Date1 = "{ts '2018-11-05 12:13:50'}";
DateTimeFormat= DateTimeFormat(Date1,"m")
DateTimeFormat1= DateTimeFormat(Date1,"mm")
DateTimeFormat2= DateTimeFormat(Date1,"mmm")
DateTimeFormat3= DateTimeFormat(Date1,"mmmm")
DateTimeFormat4= DateTimeFormat(Date1,"M")
writeOutput("Month as digits; no leading zero for single-digit months: " & DateTimeFormat & "<br/>")
writeOutput("Month as digits; leading zero for single-digit months: " & DateTimeFormat1 & "<br/>")
writeOutput(" Month as a three-letter abbreviation.: " & DateTimeFormat2 & "<br/>")
writeOutput(" Month as a three-letter abbreviation.: " & DateTimeFormat3 & "<br/>")
writeOutput(" Month in year: " & DateTimeFormat4 & "<br/>")
</cfscript>
The code sample above produces the following output:
Month as digits; no leading zero for single-digit months: 11
Month as digits; leading zero for single-digit months: 11
Month as a three-letter abbreviation.: Nov
Month as a three-letter abbreviation.: November
Month in year: 11
Sign in to your account