Date Object "JS"

Source: Internet
Author: User
Tags getdate

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.

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. <title>Date对象【js】</title>
  4. <script type="text/javascript">
  5. with(document){
  6. var date = new Date(); //启用基本存储器并取得日期和时间。
  7. write(date + "<br/>");//它代表了所保存的年份与 1900 年之间的差距。这个方法已经过时,之所以提供这个方法,是为了保持向后的兼容性。请改用 getFullYear 方法。
  8. write(date.getFullYear() + "<br/>");//返回 Date 对象中用本地时间表示的年份值。
  9. write(date.getMonth() + 1 + "<br/>");//返回 Date 对象中用本地时间表示的月份值。方法返回一个处于 0 到 11 之间的整数,它代表 Date 对象中的月
  10. write(date.getDate() + 1 + "<br/>");//返回 Date 对象中用本地时间表示的一个月中的日期值。
  11. write(date.getHours() + "<br/>");//返回 Date 对象中用本地时间表示的小时值。
  12. write(date.getMinutes() + "<br/>");//返回 Date 对象中用本地时间表示的分钟值。
  13. write(date.getSeconds() + "<br/>");//返回 Date 对象中用本地时间表示的秒钟值。
  14. write(date.getMilliseconds() + "<br/>");//返回 Date 对象中用本地时间表示的毫秒值。
  15. write(date.toLocaleString() + "<br/>");//返回一个日期,该日期使用当前区域设置并已被转换为字符串。
  16. Write("Show Current time is:" +Date.getFullYear() + "Year" + (Date.GetMonth()+1) + "Month" +Date.getDate() + "Day" +Date.getHours() + ":" +Date.getminutes() + ":" +Date.getseconds());
  17. write(");
  18. //===========================
  19. //获取系统时间
  20. function getCurrentTime(){
  21. //获取到当前的系统时间
  22. var date = new Date();
  23. //把当前系统时间拼装成指定的格式
  24. varTimeinfo=Date.getFullYear() + "Year" + (Date.GetMonth()+1) + "Month" +Date.getDate() + "Day" +Date.getHours() + ":" +Date.getminutes() + ":" +Date.getseconds();
  25. //找到span对象
  26. var spanObj = getElementById("currentTime");
  27. //设置span标签体的内容
  28. spanObj.innerHTML = timeInfo.fontcolor("red").fontsize("5px"); //innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML。
  29. //window.setTimeout("getCurrentTime()", 1000);//setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeoout()
  30. }
  31. //定时方法 :setInterval() 与 setTimeout()区别
  32. window.setInterval("getCurrentTime()", 1000);//定时方法:按照指定的周期(以毫秒计)来调用函数或计算表达式。, 第一个参数要指定调用的代码,第二个参数是每隔指定的毫秒数调用指定的代码。
  33. // window.setTimeout("getCurrentTime()", 1000);//setTimeout() 只执行 code 一次。如果要多次调用,请使用 setInterval() 或者让 code 自身再次调用 setTimeoout()
  34. }
  35. </script>
  36. <body onLoad="getCurrentTime();">
  37. 当前系统时间是:<span id="currentTime"></span>
  38. </body>
The effect is as follows:

From for notes (Wiz)

Date Object "JS"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.