Table of Contents
JavaScript Date Format: Examples
Predefined styles
var df = new DateFormat(DateFormat.SHORT, DateFormat.SHORT); var formatted = df.format(new Date());
You can additionally pass a specific locale to the constructor function, but this looks quite similar to the above example:
var df = new DateFormat(DateFormat.SHORT, DateFormat.SHORT, Locales.availableLocales.fr); var formatted = df.format(new Date());
Custom format
In the following code snippet just the day of week is returned, eg. Monday or Montag, according to the Locale setting.
var df = new DateFormat("EEEE"); // long name of the day of week var dayOfWeek = df.format(new Date());
For a complete listing of what is possible in the pattern string consult the Reference.
Complete demo
I've also provided a small script that lists all available styles for all available Locales TODO.
Back to Date Format