/* JSDate
** Copyright (c) 1999 Christopher D. Doemel
** localized a.simeray feb 2000 optimized 14 juillet
*/
function getFormattedDate(theFormat) {
var i = 0;
var lastChar = "";
var fc = "";
var fr = "";
var zDt = new Date();
theFormat = new String(theFormat);
if (theFormat.charAt(i) == "a" || theFormat.charAt(i) == "A") {
if (theFormat.indexOf("am/pm") == 0) {
fr = lcMeridiem(zDt);
i += 5;}
else if (theFormat.indexOf("AM/PM") == 0) {
fr = ucMeridiem(zDt);
i += 5;}
else if (theFormat.indexOf("a/p") == 0) {
fr = lcAbbrMeridiem(zDt);
i += 3;}
else if (theFormat.indexOf("A/P") == 0) {
fr = ucAbbrMeridiem(zDt);
i += 3;}
else {
fr = theFormat.charAt(i);
i++;}}
else if (theFormat.indexOf("dth") == 0) {
fr = getOrdinalDate(zDt);
i += 3;}
else if (theFormat.charAt(i) == "'") {
while (++i <= theFormat.length && theFormat.charAt(i) != "'") {
fr += theFormat.charAt(i);}
if (theFormat.charAt(i) == "'") { ++i };}
else {
while (i <= theFormat.length) {
if (lastChar == "") {
lastChar = theFormat.charAt(i);
fc += lastChar;
i++;
continue;}
if (lastChar == theFormat.charAt(i)) {
fc += lastChar;
i++;
continue;}
if (lastChar != theFormat.charAt(i)) {
break;}}
if (fc == "M") { fr = getOneDigitMonth(zDt); }
else if (fc == "MM") { fr = getTwoDigitMonth(zDt); }
else if (fc == "MMM") { fr = getShortMonthName(zDt); }
else if (fc == "MMMM") { fr = getLongMonthName(zDt); }
else if (fc == "d") { fr = getOneDigitDate(zDt); }
else if (fc == "dd") { fr = getTwoDigitDate(zDt); }
else if (fc == "ddd") { fr = getShortDayName(zDt); }
else if (fc == "dddd") { fr = getLongDayName(zDt); }
else if (fc == "yy") { fr = getTwoDigitYear(zDt); }
else if (fc == "yyyy") { fr = getFourDigitYear(zDt); }
else if (fc == "h") { fr = getOneDigitHour(zDt); }
else if (fc == "H") { fr = getOneDigitMilitaryHour(zDt); }
else if (fc == "hh") { fr = getTwoDigitHour(zDt); }
else if (fc == "HH") { fr = getTwoDigitMilitaryHour(zDt); }
else if (fc == "m") { fr = getOneDigitMinutes(zDt); }
else if (fc == "mm") { fr = getTwoDigitMinutes(zDt); }
else if (fc == "s") { fr = getOneDigitSeconds(zDt); }
else if (fc == "ss") { fr = getTwoDigitSeconds(zDt); }
else { fr = fc; };}
if (i == theFormat.length) { return fr; }
else { return fr + getFormattedDate(theFormat.substring(i,theFormat.length)); }}
function getDate() { return getFormattedDate("MMMM d, yyyy"); }
function getTime() { return getFormattedDate("h:mm am/pm"); }
function getOneDigitMonth(zDt) {
return zDt.getMonth() + 1;}
function getTwoDigitMonth(zDt) {
var zeM = getOneDigitMonth(zDt);
return (zeM < 10 ? "0" + zeM : zeM);}
function getShortMonthName(zDt) {
var zeM = getOneDigitMonth(zDt);
if (zeM == 1) { return "Jan"; }
else if (zeM == 2) { return "Fev"; }
else if (zeM == 3) { return "Mar"; }
else if (zeM == 4) { return "Avr"; }
else if (zeM == 5) { return "Mai"; }
else if (zeM == 6) { return "Jui"; }
else if (zeM == 7) { return "Jul"; }
else if (zeM == 8) { return "Aou"; }
else if (zeM == 9) { return "Sep"; }
else if (zeM == 10) { return "Oct"; }
else if (zeM == 11) { return "Nov"; }
else { return "Dec"; }}
function getLongMonthName(zDt) {
var zeM = getOneDigitMonth(zDt);
if (zeM == 1) { return "Janvier"; }
else if (zeM == 2) { return "F&eacute;vrier"; }
else if (zeM == 3) { return "Mars"; }
else if (zeM == 4) { return "Avril"; }
else if (zeM == 5) { return "Mai"; }
else if (zeM == 6) { return "Juin"; }
else if (zeM == 7) { return "Juillet"; }
else if (zeM == 8) { return "Aout"; }
else if (zeM == 9) { return "Septembre"; }
else if (zeM == 10) { return "Octobre"; }
else if (zeM == 11) { return "Novembre"; }
else { return "D&eacute;cembre"; }}
function getOneDigitDate(zDt) {
return zDt.getDate();}
function getOrdinalDate(zDt) {
var zeD = getOneDigitDate(zDt);
var ordDay = parseInt(zeD) % 10;
if (ordDay == 1) { return zeD + ""; }
else if (ordDay == 2) { return zeD + ""; }
else if (ordDay == 3) { return zeD + ""; }
else { return zeD + ""; }}
function getTwoDigitDate(zDt) {
var zeD = getOneDigitDate(zDt);
return (zeD < 10 ? "0" + zeD : zeD);}
function getShortDayName(zDt) {
var zeD = zDt.getDay();
if (zeD == 0) { return "Sun"; }
else if (zeD == 1) { return "Mon"; }
else if (zeD == 2) { return "Tue"; }
else if (zeD == 3) { return "Wed"; }
else if (zeD == 4) { return "Thu"; }
else if (zeD == 5) { return "Fri"; }
else { return "Sat"; }}
function getLongDayName(zDt) {
var zeD = zDt.getDay();
if (zeD == 0) { return "Dimanche"; }
else if (zeD == 1) { return "Lundi"; }
else if (zeD == 2) { return "Mardi"; }
else if (zeD == 3) { return "Mercredi"; }
else if (zeD == 4) { return "Jeudi"; }
else if (zeD == 5) { return "Vendredi"; }
else { return "Samedi"; }}
function getFourDigitYear(zDt) {
var theYear = zDt.getYear();
if (theYear < 1000) { theYear += 1900; }
return theYear;}
function getTwoDigitYear(zDt) {
var theYear = getFourDigitYear(zDt);
var strYear = new String(theYear);
return strYear.substring(2,4);}
function getOneDigitHour(zDt) {
var theHour = zDt.getHours() % 12;
if (theHour == 0) { theHour = 12; }
return theHour;}
function getTwoDigitHour(zDt) {
var theHour = getOneDigitHour(zDt);
return (theHour < 10 ? "0" + theHour : theHour);}
function getOneDigitMilitaryHour(zDt) {
return zDt.getHours();}
function getTwoDigitMilitaryHour(zDt) {
var theHour = getOneDigitMilitaryHour(zDt);
return (theHour < 10 ? "0" + theHour : theHour);}
function getOneDigitMinutes(zDt) {
return zDt.getMinutes();}
function getTwoDigitMinutes(zDt) {
var theMinutes = getOneDigitMinutes(zDt);
return (theMinutes < 10 ? "0" + theMinutes : theMinutes);}
function getOneDigitSeconds(zDt) {
return zDt.getSeconds();}
function getTwoDigitSeconds(zDt) {
var theSeconds = getOneDigitSeconds(zDt);
return (theSeconds < 10 ? "0" + theSeconds : theSeconds);}
function lcMeridiem(zDt) {
var theHour = getOneDigitMilitaryHour(zDt);
return (theHour < 12 ? "am" : "pm");}
function lcAbbrMeridiem(zDt) {
var theHour = getOneDigitMilitaryHour(zDt);
return (theHour < 12 ? "a" : "p");}
function ucMeridiem(zDt) {
var theHour = getOneDigitMilitaryHour(zDt);
return (theHour < 12 ? "AM" : "PM");}
function ucAbbrMeridiem(zDt) {
var theHour = getOneDigitMilitaryHour(zDt);
return (theHour < 12 ? "A" : "P");}
