JS Gets the current date time
var date = new Date ();d ate.getyear (); Gets the current year (2-bit) date.getfullyear (); Get the full year (4-bit) date.getmonth (); Get the current month (0-11, 0 for January) date.getdate (); Get current day (1-31) date.getday (); Get Current week x (0-6, 0 for Sunday) date.gettime (); Gets the current time (the number of milliseconds starting in 1970.1.1) date.gethours (); Gets the current number of hours (0-23) date.getminutes (); Gets the current number of minutes (0-59) date.getseconds (); Gets the current number of seconds (0-59) date.getmilliseconds (); Gets the current number of milliseconds (0-999) date.tolocaledatestring (); Get the current date as of June 25, 2014 date.tolocaletimestring (); Get current time such as PM 4:45:06date.tolocalestring (); Get date and time as June 25, 2014 4:45:06
Note: both GetYear () and getFullYear () can get the year, but the two are slightly different
GetYear () is displayed in the browser as: 114 (2014 for example), because GetYear returns the value of "Current year 1900" (that is, the year Base is 1900)
Use JS to get the year used: getFullYear ()
Timed Refresh
The timing refresh uses the setinterval, the specific settimeout and the SetInterval difference reference other material.
1, the first page needs a region for display time
<div id= "Showdate" ></div>
2. Get Time
<script type= "Text/javascript" >$ (function () {setinterval ("getTime ();", 1000);////per second)//Get system Current time function GetTime () {var mydate = new Date (), var date = mydate.tolocaledatestring (); var hours = Mydate.gethours (); var minutes = Mydat E.getminutes (); var seconds = Mydate.getseconds (); $ ("#showDate"). HTML (date+ "" +hours+ ":" +minutes+ ":" +seconds "); Assigning a value to Div}</script>
use toLocaleDateString () to get the month and date directly, do not need to obtain a separate year, month, day
While toLocaleTimeString () can be obtained directly when seconds and minutes, because the format it obtains is not required. can then be obtained separately.