Several small demos about JS control time

Source: Internet
Author: User
Tags local time time and date

First,the timing and delay method of the document comes with :
cyclic execution: var Timeid = Window.setinterval ("Method name or method", "delay"); Window.clearinterval (Timeid);
timed execution: var tmid = Window.settimeout ("Method name or method", "Time delay"); Window.cleartimeout (tmid);

Like what:


Second, Date (object)
The Date object enables you to get time and date relative to the International Standard Time (Greenwich Mean Time, now known as utc-universal coordinated times) or the operating system that the Flash player is running. To use the method of the Date object, you must first create an entity (Instance) of the Date object.

Introduction to Methods for Date objects:

 getdate | Gets the current date (the number of this month) based on local time getday | Get today is the day of the week based on local time (0-sunday,1-monday ...) getFullYear | Gets the current year (four digits) based on local time gethours | Gets the current number of hours based on local time (24-hour, 0-23) getmilliseconds | Gets the current number of milliseconds based on local time • g  Etminutes | Gets the current number of minutes based on local time getmonth | Gets the current month based on local time (note starting from 0:0-jan,1-feb ...) getseconds | Gets the current number of seconds based on local time gettime | Gets the number of milliseconds since 1970.1.1 0:00 in the UTC format gettimezoneoffset | Gets the offset value in the current time and UTC format in minutes  bit) getUTCDate | Gets the current date in UTC format (the number of this month) getUTCDay | Gets the day of the week in UTC format (0-sunday,1-monday ...)   getUTCFullYear | Gets the current year in UTC format (four digits) getUTCHours | Gets the current hour in UTC format (24-hour, 0-23) getutcmilliseconds | Gets the current number of milliseconds in UTC format  getUTCMinutes | Gets the current number of minutes in UTC format getutcmonth | Gets the current month in UTC format (note starting from 0:0-jan,1-feb ...)    getUTCSeconds | Gets the current number of seconds in UTC format getyear | Gets the current abbreviated year (current year minus 1900) based on local time setdate | Set the current date (the number of this month) setFullYear      | Set current year (four digits) sethours | Set current hours (24-hour, 0-23) setmilliseconds | Set the current number of milliseconds setminutes | Set the current number of minutes setmonth | Set the current month (note starting from 0:0-jAn,1-feb ...) setseconds | Set the current number of seconds settime | Sets the number of milliseconds since 1970.1.1 0:00 in the UTC format setutcdate | Sets the current date in UTC format (the date of the month) Setutcfull Year | Sets the current years in UTC (four digits) setutchours | Sets the current number of hours in UTC (24-hour, 0-23) setutcmilliseconds | Sets the current number of milliseconds in UTC format Setutcminu  TES | Sets the current number of minutes in UTC setUTCMonth | Sets the current month in UTC format (note starting from 0:0-jan,1-feb ...) setUTCSeconds | Sets the current number of seconds in UTC setyear | Sets the current abbreviation year (current year minus 1900) tostring | Converts a datetime value to a string value in the form of a date/time · DATE.UTC | Returns a fixed-time value for the specified UTC format date time

Here is a case of using date:

<span style= "White-space:pre" ></span>var mydate = new Date (); var year = Mydate.getyear ();    Gets the current year (2-bit) var fullyear = Mydate.getfullyear (); Get the full year (4-bit, 1970-????)       var month = Mydate.getmonth () +1; Gets the current month (0-11, 0 for January) if (month<10) {month = "0" +month;}        var date = Mydate.getdate (); Gets the current day (1-31) if (date<10) {date = "0" +date;}         var day = Mydate.getday ();        Get Current week x (0-6, 0 for Sunday) var time = Mydate.gettime ();       Gets the current time (number of milliseconds since 1970.1.1) var hours = Mydate.gethours (); Gets the current number of hours (0-23) if (hours<10) {hours = "0" +hours;}     var minutes = mydate.getminutes (); Gets the current number of minutes (0-59) if (minutes<10) {minutes = "0" +minutes;}     var seconds = mydate.getseconds (); Gets the current number of seconds (0-59) if (seconds<10) {seconds = "0" +seconds;}    var millisenconds = Mydate.getmilliseconds ();     Gets the current number of milliseconds (0-999) var localedatestring = mydate.tolocaledatestring ();     Gets the current date var mytime=mydate.tolocaletimestring ();        Get current time var localestring = mydate.tolocalestring (); Get Date and time

The source of the fall: http://blog.csdn.net/cl05300629

Several small demos about JS control time

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: info-contact@alibabacloud.com 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.