JS Generation Current Time

Source: Internet
Author: User
Tags time and seconds

Do Web pages often encounter the need to give time control to assign the current time requirements, every time you have to check the code on the Internet, more trouble, simply write down in the blog:

varMydate=NewDate (); varRealyear =mydate.getfullyear (); varMymonth = Mydate.getmonth () +1; varRealmonth=Mymonth; varMyday =mydate.getdate (); varRealday =Myday; if(mymonth<10) {Realmonth= "0" +Mymonth; }    if(myday<10) {Realday= "0" +Myday; }    varRealdate = realyear + '-' +realmonth+ '-' +Realday; $("Input[name= ' Entityvo.scrap_time ']"). Val (realdate);

Okay, I'm a lazy man.

The value obtained when getmonth is 0-11, so it needs to be +1 on the original basis.

To get the current date, you need to use GETDATE () instead of GetDay (), GetDay () Gets the current number of weeks.

All right, just put the time and seconds into it:

1     varMydate=NewDate ();2     varRealyear =mydate.getfullyear ();3     varMymonth = Mydate.getmonth () +1;4     varRealmonth=Mymonth;5     varMyday =mydate.getdate ();6     varRealday =Myday;7     varMyhour =mydate.gethours ();8     varRealhours =Myhour;9     varMyminute =mydate.getminutes ();Ten     varRealminute =Myminute; One     varMysecond =mydate.getseconds (); A     varRealsecond =Mysecond; -     if(mymonth<10){ -Realmonth= "0" +Mymonth; the     } -     if(myday<10){ -realday= "0" +Myday; -     } +     if(myminute<10){ -Realminute= "0" +Myminute; +     } A     if(myhour<10){ atrealhours= "0" +Myhour; -     } -     if(mysecond<10){ -Realsecond= "0" +Mysecond; -     } -     varRealdate = realyear + '-' +realmonth+ '-' +realday+ ' ' +realhours+ ': ' +realminute+ ': ' +Realsecond; in$ ("Input[name= ' Entityvo.scrap_time ')"). Val (realdate);

Well, after the need for the time can be directly to their own blog copy, lazy people are like this!

JS Generation Current Time

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.