Français
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <meta http-equiv="Content-Type" content
=
"text/html; charset=gb2312"> <TITLE>Formateur de date simple d'emu</TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT="emu"> <META NAME="Mots clés" CONTENT="format de formatage de date emu"> <META NAME="Description" CONTENT="Une fonction pour formater l'objet Date en chaîne"> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> < !-- Date.prototype.format = function (format){ if (format == null) format = "aaaa/MM/jj HH:mm:ss.SSS"; var année = this.getFullYear(); var mois = this.getMonth(); var sMonth = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre". "][mois]; var date = this.getDate(); var jour = this.getDay(); var hr = this.getHours(); var min = this.getMinutes(); var sec = this.getSeconds(); var joursInAnnée = Math.ceil((this-new Date(year,0,0))/86400000); var weekInYear = Math.ceil((daysInYear+new Date(year,0,1).getDay())/7); var weekInMonth = Math.ceil((date+new Date(year,month,1).getDay())/7); return format.replace("aaaa",année).replace("aa",année.toString().substr(2)).replace("jj",(date<10?"0":"")+date ).replace("HH",(hr<10?"0":"")+hr).replace("KK",(hr%12<10?"0":"")+hr%12). replace("kk",(hr>0&&hr<10?"0":"")+(((hr+23)%24)+1)).replace("hh",(hr>0&&hr<10|| h>12&&hr<22?"0":"")+(((heure+11)%12)+1)).replace("mm",(min<10?"0":"")+min) .replace("ss",(sec<10?"0":"")+sec).replace("SSS",this%1000).replace("a",(hr<12?"AM":" PM")).replace("W",weekInMonth).replace("F",Math.ceil(date/7)).replace(/E/g,["Dimanche","Lundi","Mardi", "Mercredi","Jeudi","Vendredi","Samedi"][jour]).replace("D",daysInYear).replace("w",weekInYear).replace(/MMMM+/,sMonth).replace( "MMM",sMonth.substring(0,3)).replace("MM",(mois<9?"0":"")+(mois+1)); } var d = nouvelle Date(); alert(d.format());//format par défaut alert(d.format("MM-dd-yyyy")); alert(d.format("jj/MM/aa")); alert(d.format("jj\MM\aaaa HH:mm ss.SSS")); alert(d.format("aaaa年MM月jj日 HH时mm分ss.SSS秒")); alert(d.format("aaaa年MM月jj日 E HH(0~23)时mm分ss.SSS秒")); alert(d.format("aaaaMM 月jj日 E KK(0~11)时mm分ss.SSS秒 a")); alert(d.format("aaaaMM 月jj日 E hh(1~12)时mm分ss.SSS秒 a")); alert(d.format("aaaa年MM月jj日 E kk(1~24)时mm分ss.SSS秒 今年的第D天,第w周,MMMM这个月的第W周,MMM这个月的第F个E")); //--> </SCRIPT> </BODY> </HTML>