Javascript DateFormat[%t]er Class

Using PHP strftime Format Conversion

Showcase

click the button to start or download the code below


//Given Date: Thursday, 11 March 2010 09:50:32
//Given Language: en

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

oDate.getDate({year:2010, month:3, date:11, hours:9, minutes:50, seconds:32}, %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 Thu 
 
abbreviated weekday name
%A Thursday 
 
full weekday name
%b Mar 
 
abbreviated month name
%B March 
 
full month name
%c Thu 11 Mar 2010 09:50:32 AM UTC 
 
preferred date and time
%C 20 
 
century number (range 00 to 99)
%d 11 
 
day of the month as a decimal number (range 01 to 31)
%D 03/11/10 
 
same as %m/%d/%y
%e 11 
 
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 10 
 
like %G, but without the century.
%G 2010 
 
The 4-digit year corresponding to the ISO.
%h Mar 
 
same as %b
%H 09 
 
hour as a decimal number using a 24-hour clock (range 00 to 23)
%I 09 
 
hour as a decimal number using a 12-hour clock (range 01 to 12)
%j 070 
 
day of the year as a decimal number (range 001 to 366)
%m 03 
 
month as a decimal number (range 01 to 12)
%M 50 
 
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 09:50:32 AM 
 
time in a.m. and p.m. notation
%R 09:50 
 
time in 24 hour notation
%S 32 
 
second as a decimal number
%t  
 
tab character
%T 09:50:32 
 
current time, equal to %H:%M:%S
%u
 
weekday as a decimal number [1,7], with 1 representing Monday
%U 10 
 
week number of the current year as a decimal number (%V-1)
%V 10 
 
The ISO 8601:1988 week of the current year, range 01 to 53
%W 10 
 
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 03/11/2010 
 
preferred date representation for the current locale without the time
%X 09:50:32 AM 
 
preferred time representation for the current locale without the date
%y 10 
 
year as a decimal number without a century (range 00 to 99)
%Y 2010 
 
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