Time and date are displayed in various ways on computers and networks. When the computer is turned on, the time is displayed. Some web pages also display the time when the web page was opened and the current time. In fact, this is very simple to do, and you can easily create such an effect using JavaScript scripting language. In web page production, the special effect codes for various formats of time and date are as follows:
Here is a quote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>emu's date simple date formatter</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="emu">
<META NAME="Keywords" CONTENT="date formatter format emu">
<META NAME="Description" CONTENT="A function to format Date object into String">
</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 month = this.getMonth();
var sMonth = ["January","February","March","April","May","June","July","August","September","October","November","December "][month];
var date = 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(year,month,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). replace("kk",(hr>0&&hr<10?"0":"")+(((hr+23)%24)+1)).replace("hh",(hr>0&&hr<10|| hr>12&&hr<22?"0":"")+(((hr+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", "Wednesday","Thursday","Friday","Saturday"][day]).replace("D",daysInYear).replace("w",weekInYear).replace(/MMMM+/,sMonth).replace( "MMM",sMonth.substring(0,3)).replace("MM",(month<9?"0":"")+(month+1));
}
var d = new Date();
alert(d.format());//default 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 year MM month dd day HH hour mm minute ss.SSS second"));
alert(d.format("yyyy year MM month dd day E HH (0~23) hour mm minute ss.SSS second"));
alert(d.format("yyyy year MM month dd day E KK (0~11) hour mm minute ss.SSS second a"));
alert(d.format("yyyy year MM month dd day E hh (1~12) hour mm minute ss.SSS second a"));
alert(d.format("yyyy year MM month dd day E kk (1~24) hour mm minute ss.SSS second the D day of this year, the w week, MMMM the W week of this month, MMM the Wth week of this month F E"));
//-->
</SCRIPT>
</BODY>
</HTML>
The following is the time and date displayed in pure Chinese:
Here is a quote:
<SCRIPT LANGUAGE="JavaScript">
<!--
String.prototype.toCHS=function(){return this.replace(/d/g, function(a){return "zero one two three four five six seven eight nine".charAt(parseInt(a))}); }
Number.prototype.toCHS=function(){return((this>19?Math.floor(this/10):"")+(this>9?("十"):"")+(this%10= =0&&this>0?"":this%10)).toCHS();}
Date.prototype.toCHS=function(){
with(this)return(getFullYear()+"").toCHS()+"Year"+(getMonth()+1).toCHS()+"Month"+getDate().toCHS()+"Day"+ getHours().toCHS()+"hour"+getMinutes().toCHS()+"minute"+getSeconds().toCHS()+"second";
}
alert(new Date().toCHS());
//-->
</SCRIPT>