한국어
时间日期的各种格式的特效代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <meta http-equiv="Content-Type" content= "text/html; charset=gb2312"> <TITLE>emu의 날짜 단순 날짜 포맷터</TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT="emu"> <META NAME="Keywords" CONTENT="date formatter format emu"> <META NAME="Description" CONTENT="Date 객체를 문자열로 포맷하는 함수"> </HEAD> <BODY> <SCRIPT LANGUAGE="JavaScript"> < !-- Date.prototype.format = function (format){ if (format == null) format = "yyyy/MM/dd HH:mm:ss.SSS"; var year = this.getFullYear(); var 월 = this.getMonth(); var sMonth = ["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월 "][월]; var 날짜 = this.getDate(); var day = this.getDay(); var hr = this.getHours(); var min = this.getMinutes(); var sec = this.getSeconds(); var daysInYear = 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(년,월,1).getDay())/7); return format.replace("yyyy",year).replace("yy",year.toString().substr(2)).replace("dd",(date<10?"0":"")+date ).replace("HH",(hr<10?"0":"")+hr).replace("KK",(hr%12<10?"0":"")+hr%12). replacement("kk",(hr>0&&hr<10?"0":"")+(((hr+23)%24)+1)).replace("hh",(hr>0&&hr<10|| 시간>12&&시간<22?"0":"")+(((시간+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,["Sunday","Monday","Tuesday", "수요일","목요일","금요일","토요일"][일]).replace("D",daysInYear).replace("w",weekInYear).replace(/MMMM+/,sMonth).replace( "MMM",sMonth.substring(0,3)).replace("MM",(월<9?"0":"")+(월+1)); } var d = new Date(); Alert(d.format());//기본 형식 Alert(d.format("MM-dd-yyyy")); Alert(d.format("dd/MM/yy")); Alert(d.format("dd\MM\yyyy HH:mm ss.SSS")); Alert(d.format("yyyy年MM月dd日 HH时mm分ss.SSS秒")); Alert(d.format("yyyy年MM月dd日 E HH(0~23)时mm分ss.SSS秒")); Alert(d.format("yyyy年MM月dd日 E KK(0~11)时mm分ss.SSS秒 a")); Alert(d.format("yyyy年MM月dd日 E hh(1~12)时mm分ss.SSS秒 a")); Alert(d.format("yyyy年MM月dd日 E kk(1~24)时mm分ss.SSS秒 今年的第D天,第w周,MMMM这个月的第W周,MMM这个月的第F个E")); //--> </SCRIPT> </BODY> </HTML>