Web effects four dynamic display of time date code in Web pages
Displaying the date time in a Web page is more commonly used, and I've collected four display methods that I hope will help a lot.
Take the parts and make a string connection
code example:
<script>
document.write ("<span id=time></span>")//output container showing time date
SetInterval (function () {
With (new Date)
Time.innertext=getyear () + "year" + (GetMonth () +1) + "month" +getdate () + "Day Week" + "Day 123456". CharAt (Getday ()) + "" +gethours () + ":" + getminutes () + ":" +getseconds ()
Set text within an object with ID time as the current datetime
},1000)///every 1000 milliseconds (i.e. 1 seconds) execute this code once
</script>
Method Two: Directly using the Date object's toLocaleString method to transform.
code example:
<script>
document.write ("<span id=time></span>")//output container showing time date
Execute this code once every 1000 milliseconds (or 1 seconds)
SetInterval ("Time.innertext=new Date (). toLocaleString ()", 1000)
</script>
Try this: The reader can try to use the Getday method of the Date object to add the function of the week.
Special Notes
This example is primarily in the previous example of adding a setinterval timer, updating the display time and date per second.
Related issues
How to get the week of a specified date
Adds a date parameter when declaring a Date object, for example, to obtain the week of October 1, 2000:
New Date (2000,9,1). Getday ()
Method Three
<script language=javascript>
var enabled = 0; Today = new Date ();
Var day; var date;
if (Today.getday () ==0) day = "Sunday"
if (Today.getday () ==1) day = "Monday"
if (Today.getday () ==2) day = "Tuesday"
if (Today.getday () ==3) day = "Wednesday"
if (Today.getday () ==4) day = "Thursday"
if (Today.getday () ==5) day = "Friday"
if (Today.getday () ==6) day = "Saturday"
Document.fgcolor = "Cadet";
Date1 = "<font size=2 face= Song Body color=black>" + (Today.getyear ()) + "year" + (Today.getmonth () + 1) + "month" + Today.getdat E () + "Day" + "</font>";
Date2 = "<font size=2 face= Song body color=black>" + day + "</font>";
document.write ("<right>" + date1.fontsize (2) + date2.fontsize (2) + "</right>");
</SCRIPT>
</td>
<td>
<class=t_msgfont Align=center><span id=liveclock 15px? height:30px; style?= "width:" ><font color=black size=2>17:47:26</font></span>
<script language=javascript>
function Www_helpor_net ()
{
var digital=new Date ()
var hours=digital.gethours ()
var minutes=digital.getminutes ()
var seconds=digital.getseconds ()
if (minutes<=9)
minutes= "0" +minutes
if (seconds<=9)
seconds= "0" +seconds
myclock= "<font size=2 color=black>" +hours+ ":" +minutes+ ":" +seconds+ "</font>"
if (document.layers) {document.layers.liveclock.document.write (Myclock)
Document.layers.liveclock.document.close ()
}else if (document.all)
Liveclock.innerhtml=myclock
SetTimeout ("Www_helpor_net ()", 1000)
}
Www_helpor_net ();
</SCRIPT>
Method Four
<body>
<script language= "JavaScript" >
function Disptime ()
{
var now=new Date ();
var hour=now.gethours ();
var minute=now.getminutes ();
var second=now.getseconds ();
var day=now.getday ();
var apm= "the Morning";
if (hour>12)
{
hour=hour-12;
Apm= "Afternoon";
}
if (minute<10)
{
Minute= "0" +minute;
}
if (second<10)
{
second= "0" +second;
}
document.form.text.value=hour+ "+minute+" +second+ "seconds" +APM;
SetTimeout ("Disptime ()", 1000);
}
/* Switch (Day)
{
Case 0:
document.write ("Sunday");
Break
Case 1:
document.write ("Monday");
Break
Case 2:
document.write ("Tuesday");
Break
Case 3:
document.write ("Wednesday");
Break
Case 4:
document.write ("Thursday");
Break
Case 5:
document.write ("Friday");
Break
Case 6:
document.write ("Saturday");
Break
}
*/
</script>
<form method= "POST" name= "form" >
Time <input type= "text" name= "text" value= "onfocus=" Javascript:disptime () "></input>
</form
</body>