Description
Formats the date part of a date/time value in a locale-specific format.
Returns
A formatted date/time value. If no mask is specified, the value is formatted according to the locale setting of the client computer.
Category
Syntax
LSDateFormat(date [, mask, locale])
See also
LSParseDateTime, LSTimeFormat, DateFormat, SetLocale; Handling data in ColdFusion in the Developing ColdFusion Applications
History
ColdFusion (2021 release): Added a JVM flag -Dcoldfusion.datemask.useDasdayofmonth. It defaults to false but when set to true and the mask contains D (uppercase D), the mask treats the value as d (lowercase d), day of the month. Hence, dateformat(now(), "mm-D-yyyy") is the same as dateformat(now(), "mm-d-yyyy") when flag is set to true. By default Capital D is used to specify Day of the year.
ColdFusion 8: Added the locale parameter.
ColdFusion MX:
- Changed formatting behavior: this function might return different formatting than in earlier releases. This function uses Java standard locale formatting rules on all platforms.
- Added support for the following mask parameter options: short, medium, long, and full.
Parameters
Parameter |
Description |
---|---|
date |
A date/time object, in the range 100 AD-9999 AD. |
mask |
Characters that show how ColdFusion displays the date:
|
locale |
Locale to use instead of the locale of the page when processing the function |
Usage
This function uses Java standard locale formatting rules on all platforms. When passing date/time value as a string, enclose it in quotation marks. Otherwise, it is interpreted as a number representation of a date/time object.To calculate a difference between time zones, use the GetTimeZoneInfo function.
Example
<cfscript> date = LSDateFormat(now()); date1 = LSDateFormat(now(), "mmm-dd-yyyy"); date2 = LSDateFormat(now(), "mmmm d, yyyy"); date3 = LSDateFormat(now(), "mm/dd/yyyy"); date4 = LSDateFormat(now(), "ddd, mmmm dd,yyyy"); date5 = LSDateFormat(now(), "d/m/yy"); writeOutput(date1 & "<br/>") writeOutput(date2 & "<br/>"); writeOutput(date3 & "<br/>"); writeOutput(date4 & "<br/>"); writeOutput(date5 & "<br/>");; </cfscript>
Output
Nov-06-2018
November 6, 2018
11/06/2018
Tue, November 06,2018
6/11/18
Adobe
Recevez de l’aide plus rapidement et plus facilement
Nouvel utilisateur ?