JS Get current Date Time
var date = new Date ();
Date.getyear (); Get the current year (2-bit)
date.getfullyear ();//Get Full year (4-bit, 2014)
date.getmonth ()//Get Current month (0-11, 0 for January)
Date.getdate (); Get the current day (1-31)
date.getday ();//Get Current week x (0-6, 0 for Sunday)
date.gettime ()//Get current time (milliseconds from 1970.1.1)
Date.gethours (); Gets the current number of hours (0-23)
date.getminutes ();//Get the current number of minutes (0-59)
date.getseconds ();//Get current seconds (0-59)
Date.getmilliseconds (); Gets the current number of milliseconds (0-999)
date.tolocaledatestring ();//Get the current date as June 25, 2014
date.tolocaletimestring ();//Get the current time as PM 4:45:06
date.tolocalestring ()//Get date and time such as June 25, 2014 4:45:06
Note: both getyear () and getFullYear () can get the year, but the two are slightly different
GetYear () displayed in the browser is: 114 (in 2014 years for example), because GetYear returns the current year-1900 value (that is, the year Base is 1900)
Use JS to get the year is used: getFullYear ()
Timed Refresh
Timed refresh uses setinterval, specific settimeout and setinterval to refer to other information.
1, first page needs a region to display time
<div id= "Showdate" ></div>
2. Get time
<script type= "Text/javascript" >
$ (function () {
setinterval ("GetTime ();", 1000);///Every second of the execution
})
//Get system Current time
function GetTime () {
var mydate = new Date ();
var date = mydate.tolocaledatestring ();
var hours = mydate.gethours ();
var minutes = Mydate.getminutes ();
var seconds = mydate.getseconds ();
$ ("#showDate"). HTML (date+ "+hours+": "+minutes+": "+seconds"); Assign value to div
}
</script>
Use toLocaleDateString () to get the date, no need to get the year, month, day alone
and tolocaletimestring () can be directly obtained minutes and seconds, because it gets the format is not needed. It can then be obtained separately.