JavaScript Date Format: Customizing

This section describes how to add, remove and edit locales. Knowledge about how JavaScript objects and object methods work and how they are defined would make it easier for you to mess around with the source code, but is not absolutely required.

First of all, look at the Reference to learn about the Locale object's properties and it's constructor function.

Now you have 2 choices: add a completely new Locale or inherit from an existing one.

Adding a new Locale

This is simple: copy the following snippet and paste it at the end of the source code. Then insert all the desired values between the double quotes. Note: Weekday names start with Sunday. Look at the predefined Locales for examples.

tmp = new Locale("name");
tmp.shortWeekdays = new Array("", "", "", "", "", "");
tmp.longWeekdays = new Array("", "", "", "", "", "");
tmp.shortMonths = new Array("", "", "", "", "", "", "", "", "", "", "", "");
tmp.longMonths = new Array("", "", "", "", "", "", "", "", "", "", "", "");
tmp.era = new Array("", "");
tmp.amPm = new Array("", "");
tmp.datePattern = new Array("", "", "", "", "");
tmp.timePattern = new Array("", "", "", "", "");

The newly created Locale object is then accessible through the Locale.availableLocales collection, eg. Locale.availableLocales.name. I encourage you to use the standardized ISO codes for the Locale names.

Inheriting from an existing Locale

This is even simpler: pass the parent Locale as a parameter to the constructor function, then overwrite any differing properties.

tmp = new Locale("name", parent);
tmp.[[]] = [[]]

Editing Locales

This is the simplest: edit the values you want to change. You might for example want to change all the 'y's to 'k's to avoid the y2k problem, so change:

tmp.longWeekdays = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
	"Friday", "Saturday");

to

tmp.longWeekdays = new Array("Sundak", "Mondak", "Tuesdak", "Wednesdak",
	"Fridak", "Saturdak");

Back to Date Format