This article mainly introduces the Date object of JavaScript and shares with you how to make a simple clock. Interested friends can refer to the Date type provided by JS to process the time and Date. The Date type has a series of built-in methods for obtaining and setting Date and time information. Below we are simple
This topic describes the Date type.
Let's take a look at the Date method. The following is an example:
You can try the above method by yourself. I just want to briefly demonstrate the correct output format of JS:
Var today = new Date (); // create a time Date object document. write ("The following is the world standard time output:"); document. write (today +"
"); Document. write (" The following is the local time output: "); document. write (today. toLocaleString () +"
"); Document. write ("The following is the time output that matches the Chinese:"); document. write (today. getFullYear () + "-" + (today. getMonth () + 1) + "-" + today. getDate () + "" + today. getHours () + ":" + today. getMinutes () + ":" + today. getSeconds () +"
");
The output result is:
When I see this, I think of the local clock that comes with my computer. Click the time on the taskbar and a clock will pop up:
Now that we know the Date type in JS, can we display a clock of local time and Date on the webpage?
I simply made a simple clock.
Code:
Simple watch creation based on integrated instances