Javascript DateFormat[%t]er Class

Using PHP strftime Format Conversion

Showcase

click the button to start or download the code below


//Given Date: Friday, 30 July 2010 16:52:07
//Given Language: en

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

oDate.getDate({year:2010, month:7, date:30, hours:16, minutes:52, seconds:7}, %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 Fri 
 
abbreviated weekday name
%A Friday 
 
full weekday name
%b Jul 
 
abbreviated month name
%B July 
 
full month name
%c Fri 30 Jul 2010 04:52:07 PM UTC 
 
preferred date and time
%C 20 
 
century number (range 00 to 99)
%d 30 
 
day of the month as a decimal number (range 01 to 31)
%D 07/30/10 
 
same as %m/%d/%y
%e 30 
 
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 Jul 
 
same as %b
%H 16 
 
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 211 
 
day of the year as a decimal number (range 001 to 366)
%m 07 
 
month as a decimal number (range 01 to 12)
%M 52 
 
minute as a decimal number
%n  
 
newline character (the JS returned <br />)
%p PM 
 
either `am' or `pm' according to the given time value
%r 04:52:07 PM 
 
time in a.m. and p.m. notation
%R 16:52 
 
time in 24 hour notation
%S 07 
 
second as a decimal number
%t  
 
tab character
%T 16:52:07 
 
current time, equal to %H:%M:%S
%u
 
weekday as a decimal number [1,7], with 1 representing Monday
%U 30 
 
week number of the current year as a decimal number (%V-1)
%V 30 
 
The ISO 8601:1988 week of the current year, range 01 to 53
%W 30 
 
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/30/2010 
 
preferred date representation for the current locale without the time
%X 04:52:07 PM 
 
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