First, we first get the current time:
var now=new Date (); At this point the acquisition time is a collection of days and seconds of the month, as shown in:
Then, you can remove the specific time from it:
var year=now.getfullyear (); var month=now.getmonth ()+1; var day=now.getdate (); var h=now.gethours (); var m=now.getminutes (); var s=now.getseconds ();
Note 1:getMonth () gets a 1 less month value than the actual month, so it needs to be in the back "+1";
Note that 2:getday () Gets the day of the week and is a numeric number . If we want to have the "Tuesday" format displayed, you can create an array from which to take the values from the week. Since the West is accustomed to Sunday as the beginning of the week, it is possible to do the following series:
var weekday=New Array (7) weekday[0]= "Sunday" weekday[1]= "Monday" weekday[2]= "Tuesday" weekday[3]= "Wednesday" weekday[4]= "Thursday" weekday[ 5]= "Friday" weekday[6]= "Saturday"
Note 3: The display of hours and seconds: for the sake of beauty, the usual sense of liking "00:00:00" this style. But in fact, once they are less than 10, we take the style taken as above as "0:0:0", so we can take a break for a bit, as shown in the complement processing (I represents the acquisition of time division seconds):
function checktime (i) { // complement processing if(i<10) { i= "0" +I ; } return i; }
Add: The value of gettime is in milliseconds.
Get current time getdate () Attention Point