The date of first. js
The date of JS is to use the built-in object date to operate, first create a date var date=new date (), and then you can call its API to get the month day, time division seconds and so on, this is not the focus of this article, this article focuses on how to put a string of special meaning or a number of numbers into a date type.
The most common method is the var date=new date ("2016/09/05 09:08:03");
The days before the day are separated by daily slashes, and the latter is separated by colons, and our date data is stitched together into such a string. Of course, this part of the moment can be removed, and then the date of the object will be 00 seconds of data. That is, var date=new date ("2016/09/05"); is also possible.
Second. JS Timer
The SetInterval () method, called by window, can be omitted. There are two parameters, the first parameter is the function name, there are two ways of writing, the first is the direct function name, without parentheses, the second method is the function name, with parentheses, and also in quotation marks, as a string type parameter. The second parameter is the time interval of the timer, that is, how much time the function is called, in milliseconds. One of the first parameters we recommend using the second notation, which is enclosed in parentheses, is extended with quotation marks. So we can intuitively find that this is a function, otherwise without parentheses, we think it is a variable. Example:
<!DOCTYPE HTML><HTML> <HeadLang= "en"> <MetaCharSet= "UTF-8"> <Body> <DivID= "Timediv"></Div> <Script> varTimediv=document.getElementById ("Timediv"); functionWritetime () {varDate= NewDate (); varhours=date.gethours ()< Ten ? '0' +date.gethours (): Date.gethours (); varminutes=date.getminutes ()< Ten ? '0' +date.getminutes (): Date.getminutes (); varseconds=date.getseconds ()< Ten ? '0' +date.getseconds (): Date.getseconds (); Timediv.innerhtml=hours+ ':' +minutes+ ':' +seconds; } setinterval ("writetime ()", +); </Script> </Body></HTML>
The above example outputs the current time on the page every 1 seconds.
JS Date, Timer