JS Displays the current date
Copy Code code as follows:
<script language= "Javascript" >
var datelocalweek=new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var datelocalnow=new Date ();
var datelocalyear=datelocalnow.getfullyear ();
var datelocalmonth= (datelocalmonth= "0" + (Datelocalnow.getmonth () +1)). substr (datelocalmonth.length-2,2);
var datelocalday= (datelocalday= "0" +datelocalnow.getdate ()). substr (datelocalday.length-2,2);
var datelocalweekday=datelocalweek[datelocalnow.getday ()];
document.write (datelocalyear+ "year" +datelocalmonth+ "month" +datelocalday+ "Day" + "" +datelocalweekday);
</script>
The effect of the following figure:
The corresponding JS is as follows:
Copy Code code as follows:
Create an array that holds the number of days per month
function Montharr (M0, M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11) {
This[0] = M0;
THIS[1] = M1;
This[2] = m2;
THIS[3] = m3;
THIS[4] = M4;
THIS[5] = M5;
THIS[6] = M6;
THIS[7] = M7;
THIS[8] = M8;
THIS[9] = M9;
THIS[10] = M10;
THIS[11] = M11;
}
Implement a monthly calendar
function Calendar () {
var monthnames = "Janfebmaraprmayjunjulaugsepoctnovdec";
var today = new Date ();
var ThisDay;
var monthdays = new Montharr (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
Year = Today.getyear () +1900;
ThisDay = Today.getdate ();
If ((year% 4 = 0) && (year% 100!= 0)) | | (Year% 400 = 0))
MONTHDAYS[1] = 29;
Ndays = Monthdays[today.getmonth ()];
FirstDay = Today;
Firstday.setdate (1);
Testme = Firstday.getdate ();
if (Testme = 2)
Firstday.setdate (0);
StartDay = Firstday.getday ();
var daynames = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var monthnames = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var now = new Date ();
document.write ("<div id= ' Rili ' style= ' position:absolute;width:140px;left:200px;top:50px; ') > ")
document.write ("<table width= ' 217 ' border= ' 0 ' cellspacing= ' 0 ' cellpadding= ' 2 ' bgcolor= ' #0080FF ' >")
document.write ("<TR>");
document.write ("<TD>");
document.write ("<table border= ' 0 ' cellspacing= ' 1 ' cellpadding= ' 2 ' bgcolor= ' Silver ' >");
document.write ("<tr><th colspan= ' 7 ' bgcolor= ' #C8E3FF ' >");
Document.writeln ("<font style=" FONT-SIZE:9PT; Color: #330099 ' > ' + "A.D." + now.getyear () + "year" + Monthnames[now.getmonth ()] + "" + now.getdate () + "Day" + Daynames[now . Getday ()] + "</FONT>");
Document.writeln ("</th></tr><tr><th bgcolor= ' #0080FF ' ><font style= ' font-size:9pt; Color:white ' > Day </FONT></TH> ');
Document.writeln ("<th bgcolor= ' #0080FF ' ><font style= ' font-size:9pt; Color:white ' > I </FONT></TH> ');
Document.writeln ("<th bgcolor= ' #0080FF ' ><font style= ' font-size:9pt; Color:white ' > Two </FONT></TH> ');
Document.writeln ("<th bgcolor= ' #0080FF ' ><font style= ' font-size:9pt; Color:white ' > Three </FONT></TH> ');
Document.writeln ("<th bgcolor= ' #0080FF ' ><font style= ' font-size:9pt; Color:white ' > Four </FONT></TH> ');
Document.writeln ("<th bgcolor= ' #0080FF ' ><font style= ' font-size:9pt; Color:white ' > Five </FONT></TH> ');
Document.writeln ("<th bgcolor= ' #0080FF ' ><font style= ' font-size:9pt; Color:white ' > Six </FONT></TH> ');
Document.writeln ("</TR><TR>");
column = 0;
For (i=0 i<startday; i++) {
Document.writeln ("\n<td><font style= ' font-size:9pt ' > </FONT></TD>");
column++;
}
For (I=1 i<=ndays; i++) {
if (i = = ThisDay) {
Document.writeln ("</td><td align= ' CENTER ' bgcolor= ' #FF8040 ' ><font style= ' font-size:9pt; Color: #ffffff ' ><B> ')
}
else {
Document.writeln ("</td><td bgcolor= ' #FFFFFF ' align= ' CENTER ' ><font style= ' font-size:9pt;font-family") : Arial;font-weight:bold; Color: #330066 ' > ');
}
Document.writeln (i);
if (i = = ThisDay)
Document.writeln ("</FONT></TD>")
column++;
if (column = = 7) {
Document.writeln ("<TR>");
column = 0;
}
}
Document.writeln ("<tr><td colspan= ' 7" align= ' CENTER ' valign= ' top ' bgcolor= ' #0080FF ' > ')
Document.writeln ("<form name= ' clock ' onsubmit= ' 0 ' ><font style= ' font-size:9pt;") Color: #ffffff ' > ')
Document.writeln ("Now Time: <input type= ' Text ' name= ' face ' align= ' top ' ></FONT></FORM></TD>< /tr></table> ")
Document.writeln ("</TD></TR></TABLE></div>");
}
var timerid = null;
var timerrunning = false;
function Stopclock () {
if (timerrunning)
Cleartimeout (Timerid);
Timerrunning = false;
}
Show Current Time
function Showtime () {
var now = new Date ();
var hours = now.gethours ();
var minutes = now.getminutes ();
var seconds = now.getseconds ()
var timevalue = "" + (Hours >12)? hours-12:hours)
TimeValue + + (minutes < 10)? ": 0": ":") + minutes
TimeValue + + (seconds < 10)? ": 0": ":") + seconds
TimeValue + = (hours >= 12)? "PM": "Morning"
Document.clock.face.value = TimeValue;
Timerid = settimeout ("Showtime ()", 1000)//set timeout, make time dynamic display
Timerrunning = true;
}
function Startclock () {
Stopclock ();
Showtime ();
}
Use the page to display the following:
Copy Code code as follows:
<script language= "JavaScript" type= "Text/javascript" src= "Time.js" > </script>
<body bgcolor= "#FFFFFF" onload= "Startclock (); Timerone=window.settimeout "text=" #000000 ">
<script language= "JavaScript" type= "Text/javascript" >
Calendar ();
</script>
</body>
It's OK!