Date functions #2
1. Jacob Wright javascript Date.format 2. jeanfrancois.blanc calrep => faire des fonctions plus simples et fonctionnelles : a) DateFormat (date,"s j/m/a") avec : jour de la semaine en lettres, jour du mois sur 1 et 2 chiffres, mois de l'année en lettres et sur 1 et 2 chiffres, année sur 4 chiffres. b) un convertisseur basé sur http://www.poissons52.fr/histoire/revolution1789/calendrier_v.php
by toubia95
CSS
/* http://jacwright.com/projects/javascript/date_format/ */
/*
var myDate = new Date();
alert(myDate.format('M jS, Y \\i\\s \\h\\e\\r\\e!'));
*/
/* http://jeanfrancois.blanc.online.fr/calrep.html */
JavaScript
// Simulates PHP's date function
Date.prototype.format = function (format) {
var returnStr = '';
var replace = Date.replaceChars;
for (var i = 0; i < format.length; i++) {
var curChar = format.charAt(i);
if (i - 1 >= 0 && format.charAt(i - 1) == "\\") {
returnStr += curChar;
} else if (replace[curChar]) {
returnStr += replace[curChar].call(this);
} else if (curChar != "\\") {
returnStr += curChar;
}
}
return returnStr;
};
Date.replaceChars = {
shortMonths: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil', 'Aout', 'Sept', 'Oct', 'Nov', 'Dec'],
longMonths: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
shortDays: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
longDays: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
// Day
d: function () {
return (this.getDate() < 10 ? '0' : '') + this.getDate();
},
D: function () {
return Date.replaceChars.shortDays[this.getDay()];
},
j: function () {
return this.getDate();
},
l: function () {
return Date.replaceChars.longDays[this.getDay()];
},
N: function () {
return this.getDay() + 1;
},
S: function () {
return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th')));
},
w: function () {
return this.getDay();
},
z: function () {
var d = new Date(this.getFullYear(), 0, 1);
return Math.ceil((this - d) / 86400000);
}, // Fixed now
// Week
W: function () {
var d = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - d) / 86400000) + d.getDay() + 1) / 7);
}, // Fixed now
// Month
F: function () {
...