JS gets the current date and time and my JQ examples about the date

Source: Internet
Author: User

JS obtains the current date and time and my JQ examples about the date <br/> var mydate = new date (); <br/> mydate. getyear (); // obtain the current year (2 digits) <br/> mydate. getfullyear (); // obtain the complete year (4 digits, 1970 -????) <Br/> mydate. getmonth (); // obtain the current month (0-11, 0 represents January) <br/> mydate. getdate (); // obtain the current day (1-31) <br/> mydate. getday (); // get X of the current week (0-6, 0 represents Sunday) <br/> mydate. gettime (); // obtain the current time (milliseconds starting from 1970.1.1) <br/> mydate. gethours (); // obtain the current hour (0-23) <br/> mydate. getminutes (); // get the current number of minutes (0-59) <br/> mydate. getseconds (); // obtain the current number of seconds (0-59) <br/> mydate. getmilliseconds (); // obtain the current number of milliseconds (0-999) <br/> mydate. tolocaledatestring (); // obtain the current date <br/> var mytime = mydate. tolocaletimestring (); // obtain the current time <br/> mydate. tolocalestring (); // obtain the date and time <br/> // the number of days in the current month <br/> var curmonthdays = new date (mydate. getfullyear (), (mydate. getmonth () + 1), 0 ). getdate (); <br/> */<br/> current month days <br/> var curmonthdays = new date (mydate. getfullyear (), (mydate. getmonth () + 1), 0 ). getdate (); <br/> JQ is used to generate year, month, and day drop-down box data. positioning is supported. <br/> JS part: <br/> var year = 2005; <br/> var month = 12; <br/> var day = 20; <br/> {literal} <br/> $ (document ). ready (function () {<br/> set_date_select (year, month, day); <br/> $ ('# month '). change (function () {<br/> var tmp_year = $ ("# year "). val (); <br/> var tmp_month = $ ("# month "). val (); <br/> set_date_select (tmp_year, tmp_month, 0); <br/>}); <br/> function set_date_select (year, month, day) {<br/> $ ("# year "). empty (); <br/> $ ("# month "). empty (); <br/> $ ("# Day "). empty (); <br/> // year <br/> var mydate = new date (); <br/> var year_num = mydate. getfullyear ()-1900 + 1; <br/> for (VAR I = 0; I <year_num; I ++) {<br/> var tmp_year = 1900 + I; <br/> If (tmp_year = year) <br/> $ ('# year '). append ("<option value = '" + tmp_year + "'selected = 'selected'>" + tmp_year + "</option> "); <br/> else <br/> $ ('# year '). append ("<option value = '" + tmp_year + "'>" + tmp_year + "</option> "); <br/>}< br/> // month <br/> for (VAR I = 1; I <= 12; I ++) {<br/> if (I = month) <br/> $ ('# month '). append ("<option value = '" + I + "'selected = 'selected'>" + I + "</option> "); <br/> else <br/> $ ('# month '). append ("<option value = '" + I + "'>" + I + "</option> "); <br/>}< br/> // number of days in the current month <br/> var curmonthdays = 31; <br/> If (month> 0 & month <= 12) {<br/> var curmonthdays = new date (mydate. getfullyear (), (month), 0 ). getdate (); <br/>}< br/> // day <br/> for (VAR I = 1; I <= curmonthdays; I ++) {<br/> if (I = day) <br/> $ ('# Day '). append ("<option value = '" + I + "'selected = 'selected'>" + I + "</option> "); <br/> else <br/> $ ('# Day '). append ("<option value = '" + I + "'>" + I + "</option> "); <br/>}< br/> HTML section: <br/> <select name = "year" id = "year"> </SELECT> <br/> <select name = "month" id = "month"> </ select> <br/> <select name = "day" id = "day"> </SELECT>

 

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.