Localisation

You can localise strftime by implementing the short and long forms for days of the week and months of the year, and the localised aggregates for the preferred date and time representation for your locale. You need to add your locale to the Date.ext.locales object.

Localising for french

For example, this is how we'd add French language strings to the locales object:
Date.ext.locales['fr'] = {
        a: ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'],
        A: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
        b: ['jan', 'fév', 'mar', 'avr', 'mai', 'jun', 'jui', 'aoû', 'sep', 'oct', 'nov', 'déc'],
        B: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
        c: '%a %d %b %Y %T %Z',
        p: ['', ''],
        P: ['', ''],
        x: '%d.%m.%Y',
        X: '%T'
};
The % format specifiers are all defined in formats. You can use any of those.

This locale definition may be included in your own source file, or in the HTML file including strftime.js, however it must be defined after including strftime.js

The above definition includes generic french strings and formats that are used in France. Other french speaking countries may have other representations for dates and times, so we need to override this for them. For example, Canadian french uses a Y-m-d date format, while French french uses d.m.Y. We fix this by defining Canadian french to be the same as generic french, and then override the format specifiers for x for the fr-CA locale:

Date.ext.locales['fr-CA'] = Date.ext.locales['fr'];
Date.ext.locales['fr-CA'].x = '%Y-%m-%d';
//! End french

You can now use any of the French locales at any time by setting Date.locale to "fr", "fr-FR", "fr-CA", or any other french dialect:

     var d = new Date("2008/04/22");
     d.locale = "fr";

     d.strftime("%A, %d %B == %x");
will return:
     mardi, 22 avril == 22.04.2008
While changing the locale to "fr-CA":
     d.locale = "fr-CA";

     d.strftime("%A, %d %B == %x");
will return:
     mardi, 22 avril == 2008-04-22

You can use any of the format specifiers defined at formats

The locale for all dates defaults to the value of the lang attribute of your HTML document if it is set, or to "en" otherwise.

Note:
Your locale definitions MUST be added to the locale object before calling Date.strftime .
See also:
formats for a list of format specifiers that can be used in your definitions for c, x and X.

Locale names

Locale names are defined in RFC 1766. Typically, a locale would be a two letter ISO639 defined language code and an optional ISO3166 defined country code separated by a -

eg: fr-FR, de-DE, hi-IN

See also:
http://www.ietf.org/rfc/rfc1766.txt

http://www.loc.gov/standards/iso639-2/php/code_list.php

http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm

Locale fallbacks

If a locale object corresponding to the fully specified locale isn't found, an attempt will be made to fall back to the two letter language code. If a locale object corresponding to that isn't found either, then the locale will fall back to "en". No warning will be issued.

For example, if we define a locale for de:

Date.ext.locales['de'] = {
        a: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
        A: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
        b: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
        B: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
        c: '%a %d %b %Y %T %Z',
        p: ['', ''],
        P: ['', ''],
        x: '%d.%m.%Y',
        X: '%T'
};
Then set the locale to "de-DE":
     d.locale = "de-DE";

     d.strftime("%a, %d %b");
In this case, the "de" locale will be used since "de-DE" has not been defined:
     Di, 22 Apr

Swiss german will return the same since it will also fall back to "de":

     d.locale = "de-CH";

     d.strftime("%a, %d %b");
     Di, 22 Apr

We need to override the a specifier for Swiss german, since it's different from German german:

Date.ext.locales['de-CH'] = Date.ext.locales['de'];
Date.ext.locales['de-CH'].a = ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam'];
//! End german
We now get the correct results:
     d.locale = "de-CH";

     d.strftime("%a, %d %b");
     Die, 22 Apr

Built in locales

This library comes with pre-defined locales for en, en-GB, en-US and en-AU.

Generated on Tue Jun 17 22:31:26 2008 for strftime by  doxygen 1.5.5