Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Date:toLocaleFormat

From MDC


Contents

[edit] Summary

Converts a date to a string using the specified formatting.

Method of Date
Implemented in: JavaScript 1.6
ECMA Version: none

[edit] Syntax

var formattedDateString = dateObj.toLocaleFormat(formatString);

[edit] Parameters

formatString 
A format string in the same format expected by the strftime() function in C.

[edit] Description

The toLocaleFormat() provides greater software control over the formatting of the generated date and/or time. Names for months and days of the week are localized using the operating system's locale. However, ordering of the day and month and other localization tasks are not handled automatically since you have control over the order in which they occur.

[edit] Examples

[edit] Example: Using toLocaleFormat

var today = new Date();
var date = today.toLocaleFormat("%A, %B %e, %Y");

In this example, toLocaleFormat() returns a string such as "Wednesday, October 3, 2007".

[edit] See Also

toGMTString, toUTCString, toLocaleDateString toLocaleString