strftime.js File Reference

Javascript implementation of strftime. More...

Go to the source code of this file.

Variables

Date ext = {}
 Date extension object - all supporting objects go in here.
Date ext util = {}
 Utility methods.
Date ext util xPad
 Left pad a number with something.
Date prototype locale = 'en-GB'
 Currently selected locale.
Date ext locales = { }
 Localised strings for days of the week and months of the year.
Date ext locales en
 Localised strings for English (British).
Date ext formats
 List of supported format specifiers.
Date ext aggregates
 List of aggregate format specifiers.
Date ext unsupported = { }
Date prototype strftime
 Formats the date according to the specified format.


Detailed Description

Javascript implementation of strftime.

Author:
Philip S Tellis <philip@bluesmoon.info>
Version:
1.3
Date:
2008/06 Implements strftime for the Date object in javascript based on the PHP implementation described at http://www.php.net/strftime This is in turn based on the Open Group specification defined at http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html This implementation does not include modified conversion specifiers (i.e., Ex and Ox)
The following format specifiers are supported:

List of supported format specifiers.

%a, %A, %b and %B should be localised for non-English locales.

Usage:
This library may be used as follows:
     var d = new Date();

     var ymd = d.strftime('%Y/%m/%d');
     var iso = d.strftime('%Y-%m-%dT%H:%M:%S%z');
See also:
Date.strftime for a description of each of the supported format specifiers

Date.ext.locales for localisation information

http://www.php.net/strftime for the PHP implementation which is the basis for this

http://tech.bluesmoon.info/2008/04/strftime-in-javascript.html for feedback

Definition in file strftime.js.


Variable Documentation

Initial value:

 {
        c: 'locale',
        D: '%m/%d/%y',
        h: '%b',
        n: '\n',
        r: '%I:%M:%S %p',
        R: '%H:%M',
        t: '\t',
        T: '%H:%M:%S',
        x: 'locale',
        X: 'locale'
}
List of aggregate format specifiers.

Aggregate format specifiers map to a combination of basic format specifiers. These are implemented in terms of Date.ext.formats.

A format specifier that maps to 'locale' is read from Date.ext.locales[current-locale].

See also:
Date.ext.formats

Definition at line 299 of file strftime.js.

Date ext locales en

Initial value:

 {
        a: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        A: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
        b: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        B: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        c: '%a %d %b %Y %T %Z',
        p: ['AM', 'PM'],
        P: ['am', 'pm'],
        x: '%d/%m/%y',
        X: '%T'
}
Localised strings for English (British).

This will be used for any of the English dialects unless overridden by a country specific one. This is the default locale if none specified

Definition at line 136 of file strftime.js.

Date ext formats

List of supported format specifiers.

  • %a - abbreviated weekday name according to the current locale
  • %A - full weekday name according to the current locale
  • %b - abbreviated month name according to the current locale
  • %B - full month name according to the current locale
  • %c - preferred date and time representation for the current locale
  • %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
  • %d - day of the month as a decimal number (range 01 to 31)
  • %D - same as m/d/y
  • %e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
  • %g - like G, but without the century
  • %G - The 4-digit year corresponding to the ISO week number
  • %h - same as b
  • %H - hour as a decimal number using a 24-hour clock (range 00 to 23)
  • %I - hour as a decimal number using a 12-hour clock (range 01 to 12)
  • %j - day of the year as a decimal number (range 001 to 366)
  • %m - month as a decimal number (range 01 to 12)
  • %M - minute as a decimal number
  • %n - newline character
  • %p - either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale
  • %P - like p, but lower case
  • %r - time in a.m. and p.m. notation equal to I:M:S p
  • %R - time in 24 hour notation equal to H:M
  • %S - second as a decimal number
  • %t - tab character
  • %T - current time, equal to H:M:S
  • %u - weekday as a decimal number [1,7], with 1 representing Monday
  • %U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
  • %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
  • %w - day of the week as a decimal, Sunday being 0
  • %W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
  • %x - preferred date representation for the current locale without the time
  • %X - preferred time representation for the current locale without the date
  • %y - year as a decimal number without a century (range 00 to 99)
  • %Y - year as a decimal number including the century
  • %z - numerical time zone representation
  • %Z - time zone name or abbreviation
  • %% - a literal `%' character

Definition at line 207 of file strftime.js.

Date prototype locale = 'en-GB'

Currently selected locale.

The locale for a specific date object may be changed using

 Date.locale = "new-locale"; 
The default will be based on the lang attribute of the HTML tag of your document

Definition at line 96 of file strftime.js.

Date ext locales = { }

Localised strings for days of the week and months of the year.

To create your own local strings, add a locale object to the locales object. The key of your object should be the same as your locale name. For example: en-US, fr, fr-CH, de-DE Names are case sensitive and are described at http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes Your locale object must contain the following keys:

Parameters:
a Short names of days of week starting with Sunday
A Long names days of week starting with Sunday
b Short names of months of the year starting with January
B Long names of months of the year starting with February
c The preferred date and time representation in your locale
p AM or PM in your locale
P am or pm in your locale
x The preferred date representation for the current locale without the time.
X The preferred time representation for the current locale without the date.
See also:
Date.ext.locales.en for a sample implementation

Localisation for detailed documentation on localising strftime for your own locale

Definition at line 128 of file strftime.js.

Date prototype strftime

Formats the date according to the specified format.

Parameters:
fmt The format to format the date in. This may be a combination of the following: List of supported format specifiers.

  • %a - abbreviated weekday name according to the current locale
  • %A - full weekday name according to the current locale
  • %b - abbreviated month name according to the current locale
  • %B - full month name according to the current locale
  • %c - preferred date and time representation for the current locale
  • %C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
  • %d - day of the month as a decimal number (range 01 to 31)
  • %D - same as m/d/y
  • %e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
  • %g - like G, but without the century
  • %G - The 4-digit year corresponding to the ISO week number
  • %h - same as b
  • %H - hour as a decimal number using a 24-hour clock (range 00 to 23)
  • %I - hour as a decimal number using a 12-hour clock (range 01 to 12)
  • %j - day of the year as a decimal number (range 001 to 366)
  • %m - month as a decimal number (range 01 to 12)
  • %M - minute as a decimal number
  • %n - newline character
  • %p - either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale
  • %P - like p, but lower case
  • %r - time in a.m. and p.m. notation equal to I:M:S p
  • %R - time in 24 hour notation equal to H:M
  • %S - second as a decimal number
  • %t - tab character
  • %T - current time, equal to H:M:S
  • %u - weekday as a decimal number [1,7], with 1 representing Monday
  • %U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
  • %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
  • %w - day of the week as a decimal, Sunday being 0
  • %W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
  • %x - preferred date representation for the current locale without the time
  • %X - preferred time representation for the current locale without the date
  • %y - year as a decimal number without a century (range 00 to 99)
  • %Y - year as a decimal number including the century
  • %z - numerical time zone representation
  • %Z - time zone name or abbreviation
  • %% - a literal `%' character
Returns:
A string representation of the date formatted based on the passed in parameter
See also:
http://www.php.net/strftime for documentation on format specifiers

Definition at line 335 of file strftime.js.

Date ext unsupported = { }

List of unsupported format specifiers.

All format specifiers supported by the PHP implementation are supported by this javascript implementation.

Definition at line 324 of file strftime.js.

Date ext util xPad

Initial value:

function(x, pad, r)
{
        if(typeof(r) == 'undefined')
        {
                r=10;
        }
        for( ; parseInt(x, 10)<r && r>1; r/=10)
                x = pad.toString() + x;
        return x.toString();
}
Left pad a number with something.

Takes a number and pads it to the left with the passed in pad character

Parameters:
x The number to pad
pad The string to pad with
r [optional] Upper limit for pad. A value of 10 pads to 2 digits, a value of 100 pads to 3 digits. Default is 10.
Returns:
The number left padded with the pad character. This function returns a string and not a number.

Definition at line 79 of file strftime.js.


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