Recently I wrote a countdown program, because it often needs to be accessed on the mobile phone end, so jquery is not referenced. I am not used to jquery. The following describes the js date-related functions and the principle of countdown.
The Code is as follows:
Var dateTo = new Date ("8:00 1/4/2014 ");
Gets the time object of the specified date. If it is null, the default value is the current time.
The Code is as follows:
Var date = dateTo. getTime ()
Returns the number of milliseconds. the start and end time is the time of January 1, 1970.
The Code is as follows:
Var y = date. getFullYear ();
Get year
The Code is as follows:
Var mm = date. getMonth () + 1;
Get month
The Code is as follows:
Var d = date. getDate ();
Get date
The Code is as follows:
Var h = date. getHours ();
Hours
The Code is as follows:
Var m = date. getMinutes ();
Get minutes
The Code is as follows:
Var s = date. getSeconds ();
Get seconds
The idea of Countdown is to calculate the time difference between the two times, and then use
SetInterval (); execute the corresponding function once per second.
The following functions may be used in this process:
ParseInt ($ trNum );
This function converts a number of the string type into a number.