JS Get system Current Time getFullYear () and getyear ()

Source: Internet
Author: User

The Date object has two methods of obtaining the Year:getFullYear () and getyear ()

Tested var dt = new Date ();

Alert (Dt.getyear ()): IE pop-up: Firefox browser popup: 117 (GetYear () returned in Firefox is the year from January 1, 1990, this is an outdated but not recommended method);

Alert (Dt.getfullyear ()): Two browser pop-ups are: 2017

Therefore, getFullYear () should be used instead of the getyear () method at any time;

Example:

For example the current is 2017

getFullYear () Returns the result: 2017

GetYear () The result returned is: 117 (2017-1990=117)

The following is the front end to get the current system time

varEndTime;
varBeginTime;
varDT =NewDate ();
varYear=dt.getfullyear ();
varMonth=dt.getmonth (+1);//The month obtained is from 0-11
var Day = Dt.getdate ();
if (month<10) {
endtime=year+"-"+"0"+month;
}else{
endtime=year+"-"+month;
}
if (day<10) {
EndTime + ="-"+"0"+day;
}else{
EndTime + ="-"+day;
}
begintime=year+"-"+" the"+"-"+" the";//Get the Year _ _ _ _-01-01

JS Get system Current Time getFullYear () and getyear ()

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.