Javascript DateFormat[%t]er Class

Using PHP strftime Format Conversion

Showcase

click the button to start or download the code below


//Given Date: Saturday, 04 July 2009 04:39:20
//Given Language: en

var oDate = new DateFormat({lang:'en'});

oDate.getDate({year:2009, month:7, date:4, hours:4, minutes:39, seconds:20}, %m-%d-%Y);
//output mm-dd-yyyy

oDate.toFormat('%B, %Y');
//output Month, yyyy

Format PHP#strftime
(server side time)
#toFormat (%X)
(client side time)
Description
%%
 
output percentage %
%a Sat 
 
abbreviated weekday name
%A Saturday 
 
full weekday name
%b Jul 
 
abbreviated month name
%B July 
 
full month name
%c Sat 04 Jul 2009 04:39:20 AM UTC 
 
preferred date and time
%C 20 
 
century number (range 00 to 99)
%d 04 
 
day of the month as a decimal number (range 01 to 31)
%D 07/04/09 
 
same as %m/%d/%y
%e
 
day of the month as a single digit (range ' 1' to '31')
%F -
 
%F format not found in PHP. I add a new one, to calculate the week of month
%g 09 
 
like %G, but without the century.
%G 2009 
 
The 4-digit year corresponding to the ISO.
%h Jul 
 
same as %b
%H 04 
 
hour as a decimal number using a 24-hour clock (range 00 to 23)
%I 04 
 
hour as a decimal number using a 12-hour clock (range 01 to 12)
%j 185 
 
day of the year as a decimal number (range 001 to 366)
%m 07 
 
month as a decimal number (range 01 to 12)
%M 39 
 
minute as a decimal number
%n  
 
newline character (the JS returned <br />)
%p AM 
 
either `am' or `pm' according to the given time value
%r 04:39:20 AM 
 
time in a.m. and p.m. notation
%R 04:39 
 
time in 24 hour notation
%S 20 
 
second as a decimal number
%t  
 
tab character
%T 04:39:20 
 
current time, equal to %H:%M:%S
%u
 
weekday as a decimal number [1,7], with 1 representing Monday
%U 26 
 
week number of the current year as a decimal number (%V-1)
%V 27 
 
The ISO 8601:1988 week of the current year, range 01 to 53
%W 26 
 
In PHP, this format same as %U. But I choose to make it same as %V (see above)
%w
 
day of the week as a decimal, Sunday being 0
%x 07/04/2009 
 
preferred date representation for the current locale without the time
%X 04:39:20 AM 
 
preferred time representation for the current locale without the date
%y 09 
 
year as a decimal number without a century (range 00 to 99)
%Y 2009 
 
year as a decimal number including the century
%Z UTC 
 
time zone or name or abbreviation
%z +0000 
 
same as above

About (prototype version)

Date: 8 September 2008

I have heard prototype.js for long time, but I avoid to use any javascript library for the sake of my skill (or my ego?). But at least I have to deal with a project that use prototype.js as main library. So, I download it (version 1.6.0.2) along with scriptaculous.js. Please be patient with me (my script), because I just learn prototype for few days and try to play and making some fun.

Download

This example using DateFormat prototype version. But there is also a standard version that not required prototype. To download the code, you can find it here: Javascript DateFormat.

Copyright 2008 (c) Zaenal Muttaqin - Lokamaya.com
This script listed at:
Listed at Hotscripts