LSDateFormat

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

LSParseDateTimeLSTimeFormatDateFormatSetLocaleHandling 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:

  • d: Day of month. Digits; no leading zero for single-digit days
  • dd: Day of month. Digits; leading zero for single-digit days
  • ddd: Day of week, abbreviation
  • dddd: Day of week. Full name
  • D: Day in a year
  • m: Month. Digits; no leading zero for single-digit months
  • mm: Month. Digits; leading zero for single-digit months
  • mmm: Month. abbreviation (if appropriate)
  • mmmm: Month. Full name
  • y: Year. Last two digits; no leading zero for years less than 10
  • yy: Year. Last two digits; leading zero for years less than 10
  • yyyy: Year. Four digits
  • gg: Period/era string. Not processed. Reserved for future use
    The following conform to Java locale-specific time encoding standards. Their exact formats depend on the locale:
  • short: dd, mm, and yy separated by / marks
  • medium: text format using mmm, d, and yyyy
  • long: text format using mmmm, d, and yyyy
  • full: text format using dddd, mmmm, d, and yyyy
    The default value is mediumFor more information on formats, see LSParseDateTime.

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

Get help faster and easier

New user?

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX 2024

Adobe MAX
The Creativity Conference

Oct 14–16 Miami Beach and online

Adobe MAX

The Creativity Conference

Oct 14–16 Miami Beach and online