Archive
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()
Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
The non-standard toLocaleFormat()
method converts a date to a string using the specified formatting. Intl.DateTimeFormat
is an alternative to format dates in a standards-compliant way. See also the newer version of Date.prototype.toLocaleDateString()
.
This feature has been removed and will no longer work in Firefox 58+. See Warning: Date.prototype.toLocaleFormat is deprecated for more information and migration help.
dateObj.toLocaleFormat(formatString)
formatString
strftime()
function in C.A string representing the given date using the specified formatting.
The toLocaleFormat()
method 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. You should take care that the format string is localized properly according to the user's system settings. Be aware that the locale used is not necessarily the same as the locale of the browser.
Extension and XULRunner developers should know that just loading the format string from a .dtd
or .properties
file using a chrome://somedomain/locale/somefile.ext
URI should be avoided, as the .dtd
/.properties
file and the toLocaleFormat()
method does not not necessarily use the same locale, which could result in odd looking or even ambiguous or unreadable dates.
Also note that the behavior of the used locale depends on the platform, and the user might customize the locale used, so using the system locale the choose the format string might in some cases not even be adequate. You might consider using some of the more general toLocale*
methods of the Date
object or doing your own custom localization of the date to be displayed using some of the get*
methods of the Date
object instead of using this method.
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". Note that the format string in this example is not properly localized, which will result in the problems described above.
When using the DateJS library you can polyfill Date.prototype.toLocaleDateString()
like this:
if (!Date.prototype.toLocaleFormat) { (function() { Date.prototype.toLocaleFormat = function(formatString) { return this.format(formatString); }; }()); }
Not part of any standard.
Not supported in any browser. Previously supported in Firefox 1.5 until Firefox 57 (January 2018).