Date.js

An extension for JavaScript’s build-in Date class, that adds localized format, parse, week numbering functionality and more (see documentation). The parsing/formatting uses patterns compatible with java.text.SimpleDateFormat. The main source file only includes localizations for en-US and iso, but new localization can easily be added through external files, see below. Contact me if you wan’t a particular localization made or you have made one you’ll like to share.

Simple and initiative usage:

var nowDate = new Date();
var dateString = nowDate.format('yyyy-MM-dd HH:mm:ss', 'en');
var parsedDate = Date.parse(dateString, 'yyyy-MM-dd HH:mm:ss', 'en');

Test it out here.

Documentation

The generated online documentation can be found here.

Changelog

Download

License

GNU Lesser General Public License <http://www.gnu.org/licenses/lgpl-3.0.txt>

Author

Henrik Lindqvist <henrik.lindqvist@llamalab.com>

Comments


  1. localization content for Simplified Chinese



    d.i18n['zh'] =
    d.i18n['zh_CN'] = {
    months: {
    abbr: [ '\u4e00\u6708', '\u4e8c\u6708', '\u4e09\u6708', '\u56db\u6708', '\u4e94\u6708', '\u516d\u6708', '\u4e03\u6708', '\u516b\u6708', '\u4e5d\u6708', '\u5341\u6708', '\u5341\u4e00\u6708', '\u5341\u4e8c\u6708' ],
    full: [ '\u4e00\u6708', '\u4e8c\u6708', '\u4e09\u6708', '\u56db\u6708', '\u4e94\u6708', '\u516d\u6708', '\u4e03\u6708', '\u516b\u6708', '\u4e5d\u6708', '\u5341\u6708', '\u5341\u4e00\u6708', '\u5341\u4e8c\u6708' ]
    },
    days: {
    abbr: [ '\u5468\u65e5', '\u5468\u4e00', '\u5468\u4e8c', '\u5468\u4e09', '\u5468\u56db', '\u5468\u4e94', '\u5468\u516d' ],
    full: [ '\u661f\u671f\u65e5', '\u661f\u671f\u4e00', '\u661f\u671f\u4e8c', '\u661f\u671f\u4e09', '\u661f\u671f\u56db', '\u661f\u671f\u4e94', '\u661f\u671f\u516d' ]
    },
    week: { // Used by date pickers
    abbr: '\u5468',
    full: '\u671f\u65e5'
    },
    ad: '\u516c\u5143\u524d',
    am: '\u4e0a\u5348',
    pm: '\u4e0b\u5348',
    gmt: '\u683c\u6797\u5a01\u6cbb\u6807\u51c6\u65f6\u95f4',
    z: ':', // Hour - minute separator
    Z: '', // Hour - minute separator
    fdow: 0, // First day of week
    mdifw: 1 // Minimum days in first week
    };
    2. by Delsun Foo on
    Monday, 07 March 2011 at 11:09 GMT
  2. Thanks to everyone who sent localization files.
    1. by Henrik Lindqvist on
    Tuesday, 14 July 2009 at 20:55 GMT

Comment

Enter the code visible here into the Code field
> Delete | Edit