common methods for Date objects:Year: getFullYear (); Month: GetMonth () + 1; Note: the value. The method returns an integer from 0 to 11, so according to China's custom, it should be followed + 1st: GetDate (); Time: GetHours (); Points: getminutes ();
Seconds: getseconds ();
....................
the way JavaScript calls functions at timed intervals:The timing Method 1:setinterval ("The function to invoke or the code string to execute", periodically executes or calls the time interval between code, in milliseconds ");
Timing Method 2:
SetTimeout ("The JavaScript code string to execute after the function to invoke", "the number of milliseconds to wait before executing the code.") ");
InnerHTMLProperty sets or returns the HTML between the start and end tags of a table row.
For example: Locate the Span object
var spanobj = getElementById ("CurrentTime");
Set the contents of a span tag bodyspanobj.innerhtml = Timeinfo.fontcolor ("Red"). FontSize ("5px"); The InnerHTML property sets or returns the HTML between the start and end tags of a table row.
Note:
1. The first parameter of the timing method above should be enclosed in quotation marks (including functions), and the second argument can be enclosed in parentheses or not.
2.setTimeout () executes code only once. If you want to call more than once, use SetInterval () or let code itself call SetTimeout () again.
Demo:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Date对象【js】</title>
<script type="text/javascript">
with(document){
var date = new Date(); //启用基本存储器并取得日期和时间。
write(date + "<br/>");//它代表了所保存的年份与 1900 年之间的差距。这个方法已经过时,之所以提供这个方法,是为了保持向后的兼容性。请改用 getFullYear 方法。
write(date.getFullYear() + "<br/>");//返回 Date 对象中用本地时间表示的年份值。
write(date.getMonth() + 1 + "<br/>");//返回 Date 对象中用本地时间表示的月份值。方法返回一个处于 0 到 11 之间的整数,它代表 Date 对象中的月
write(date.getDate() + 1 + "<br/>");//返回 Date 对象中用本地时间表示的一个月中的日期值。
write(date.getHours() + "<br/>");//返回 Date 对象中用本地时间表示的小时值。
write(date.getMinutes() + "<br/>");//返回 Date 对象中用本地时间表示的分钟值。
write(date.getSeconds() + "<br/>");//返回 Date 对象中用本地时间表示的秒钟值。
write(date.getMilliseconds() + "<br/>");//返回 Date 对象中用本地时间表示的毫秒值。
write(date.toLocaleString() + "<br/>");//返回一个日期,该日期使用当前区域设置并已被转换为字符串。
Write("Show Current time is:" +Date.getFullYear() + "Year" + (Date.GetMonth()+1) + "Month" +Date.getDate() + "Day" +Date.getHours() + ":" +Date.getminutes() + ":" +Date.getseconds());
write(");
//===========================
//获取系统时间
function getCurrentTime(){
//获取到当前的系统时间
var date = new Date();
//把当前系统时间拼装成指定的格式
varTimeinfo=Date.getFullYear() + "Year" + (Date.GetMonth()+1) + "Month" +Date.getDate() + "Day" +Date.getHours() + ":" +Date.getminutes() + ":" +Date.getseconds();
//找到span对象
var spanObj = getElementById("currentTime");
//设置span标签体的内容
spanObj.innerHTML = timeInfo.fontcolor("red").fontsize("5px"); //innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML。
//window.setTimeout("getCurrentTime()", 1000);//setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeoout()
}
//定时方法 :setInterval() 与 setTimeout()区别
window.setInterval("getCurrentTime()", 1000);//定时方法:按照指定的周期(以毫秒计)来调用函数或计算表达式。, 第一个参数要指定调用的代码,第二个参数是每隔指定的毫秒数调用指定的代码。
// window.setTimeout("getCurrentTime()", 1000);//setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeoout()
}
</script>
<body onLoad="getCurrentTime();">
当前系统时间是:<span id="currentTime"></span>
</body>
The effect is as follows:
From for notes (Wiz)
Date Object "JS"