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 since 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: getYear () and getFullYear () are able to 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
Timed refresh use SetInterval, detailed settimeout and setinterval differences for other information.
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);//Run once every 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 obtain the date directly, no need to get the year, month, day alone
and tolocaletimestring () can be directly obtained when seconds. Because the format it gets is not required. can then be obtained separately.
JS Gets the current date time and refreshes periodically