Get current time getdate () Attention Point

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.