JavaScript function calls

Source: Internet
Author: User

"Get" date, creation time1 Mastering how to create Date objectsCreate a Date object syntax: new date (); function: Creates a DateTime object that returns a value: Returns the current DateTime object without passing a parameter. Note: If you want to create a Date object based on a specific date and time, you must pass in the number of milliseconds that represent the date or a comma-separated set of 2 days and seconds. The method of acquiring DateTime in a Date objectget the method of day, minute and week. 1getFullYear (): Returns a 4-digit year2getMonth (): Returns the month of the date with a return value of 0-113getDate (): Returns the number of days in the month4GetDay (): Returns the week with a return value of 0-65getHours (): Return hour6,getminutes (): Return minute7,getseconds (): Return seconds8getTime (): Returns the number of milliseconds that represent the date <script>//Create a DateTime object var weeks=["Day", "one", "two", "three", "four", "five", "Six"],today=new date (), Year=today.getfullyear (), MO Nth=today.getmonth () +1,date=today.getdate (), Week=today.getday (). Hours=today.gethours (), minutes= Today.getminutes (), Seconds=today.getseconds (), Times=today.gettime (), time=year+ "year" +month+ "month" +date+ "Day" +hours+ "when" +minutes+ "Minute" +seconds+ "Second Week" +weeks[week];console.log ("Now is:" +time); Console.log (times); Return: Now is the day of the month, minutes, minutes, weeks. There are also milliseconds. , the number of milliseconds from 1970 you start adding to the present. 3Learn how to set the date time in the Date object, and then set the method for the day, minute, and week. 1setFullYear (year): Set 4-digit years2setmonth (Mon): Sets the month of the date, starting at 0, 0 for January3, SetDate (): Set Date4, Setday (): Set week, starting from 0, 0 = Sunday5, Sethours (): Set hour6setminutes (): Set points7setseconds (); Set seconds8settime (): The number of milliseconds to set the date will change the entire date Create a Date object var today=new date ();//today.setfullyear; Today.setmonth (8); Console.log (Today.getmonth ());//return: September Create a DateTime object var today=new date ();//today.setfullyear; today.setmonth; Console.log (Today.getmonth ());// Returns: The month takes the remainder 13/12=1 months, and the year +1 has the ability to automatically fault-tolerant. Returning to January, the year is also increasing by one year. The first type:The current day plus 50, which is 50 days after the day of the week. Today.setdate (Today.getdate () +50); Console.log (Today.getday ()); Return value: Day of the week. The second method, Var weeks=["Day", "one", "two", "three", "four", "five", "Six"];var year=today.getfullyear (); var month=today.getmonth (); var day=t Oday.getdate ();//Create a target date object, year, month, day, time, minute, second var temp=new Date (Year+1,month,day);//year plus 1, month plus, day leave 50. Can be judged Console.log (" 50 days later to today is: "+temp.getfullyear () +"-"+ (Temp.getmonth () +1) +"-"+temp.getdate () +"-"+" Week "+weeks[temp.getday ()]); Problem, any function to create the time, and the operation of the function. The first step: the page popup input box, prompted to enter the employee's entry year, month, day, the second step: Write the function, used to encapsulate the "Employee entry time, contract expiry time" code, parameters for the user input content the following three, four or five steps are performed in the third step in the function: Create a Date object, use the variable to receive it ; Fourth step: (1) Call the method of the Date object, set the year, month, and day respectively for the employee to enter the employment of the year, Month, day (2) According to: page to output the employee's entry date Fifth step: (1) Create a target Date object (2) Call the method of the object, set the year to 3 years later (3) : The expiration date of the employee contract is printed in the page sixth step: Call Function Task Tip (1) The data entered in the page is a string, because the following steps involve operations, so the input box to convert the data type into a number (2) parameter is 3, respectively, the employee's entry year, month, Day (3) The time the user gets to n days is the method to invoke the year, month, day, and week of the date object created in step fifth var max1=prompt ("Enter the employee entry year");//pop-up window input year var max2=prompt ("Please enter the employee entry month");//Enter the month var max3=prompt ("Please enter the employee entry date");// Enter Day document.write ("Employee entry time is:" +max1+ "--" +max2+ "--" +max3+ "<br>"), function Add () {var today=new Date (Max1,max2, MAX3); Set your own date and date Var year=today.setfullyear (Today.getfullyear (MAX1) +3);d ocument.write ("Output expires" + "--" +today.getfullyear () + "--" +max2+ "--" +max3 ";} Add ();//Ask the teacher to answer.

JavaScript function calls

Related Article

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.