Javascript learning, javascript

Source: Internet
Author: User

Javascript learning, javascript

The Date function of js is very powerful. Generally used.


First obtain the current date:

Var CurDate = new Date (); var Year = CurDate. getFullYear (); // Year (four-digit example: 2014) var Month = CurDate. getMonth () + 1; // month 0 ~ 11var Day = CurDate. getDate (); // obtain the number 1 ~ 31var week = CurDate. getDay (); // obtain the number of weeks from 0 ~ 6. 0 indicates Sunday, 1 indicates Monday.

In this way, the date can be obtained.

Date (). getYear () // returns the last two digits of the year

This should not be used much.


new Date("month dd,yyyy hh:mm:ss");new Date("month dd,yyyy");new Date(yyyy,mth,dd,hh,mm,ss);new Date(yyyy,mth,dd);new Date(ms);

These methods are used to create date objects. y indicates the year, m indicates the month, d indicates the day, mm indicates the minute, and ss indicates the second. Remember to pay attention to the month: 0 ~ 11


Method description Date () returns the Date and time of the current day. GetDate () returns a day (1 ~ 31 ). GetDay () returns a day of a week from the Date object (0 ~ 6 ). GetMonth () returns the month from the Date object (0 ~ 11 ). GetFullYear () returns the year from the Date object in four digits. Use the getFullYear () method instead of getYear. GetHours () returns the hour of the Date object (0 ~ 23 ). GetMinutes () returns the minute of the Date object (0 ~ 59 ). GetSeconds () returns the number of seconds of the Date object (0 ~ 59 ). GetMilliseconds () returns the millisecond (0 ~) of the Date object ~ 999 ). GetTime () returns the number of milliseconds since January 1, January 1, 1970. GetTimezoneOffset () returns the minute difference between the local time and Greenwich Mean Time (GMT. GetUTCDate () returns the Day (1 ~ 31 ). GetUTCDay () returns the day of the week (0 ~ 6 ). GetUTCMonth () returns the month (0 ~ 11 ). GetUTCFullYear () returns the four-digit year from the Date object based on the universal time. GetUTCHours () returns the hour of the Date object based on the Universal Time (0 ~ 23 ). GetUTCMinutes () returns the minute of the Date object based on the Universal Time (0 ~ 59 ). GetUTCSeconds () returns the second of the Date object based on the Universal Time (0 ~ 59 ). GetUTCMilliseconds () returns the millisecond (0 ~ 999 ). Parse () returns the number of milliseconds from midnight, January 1, January 1, 1970 to the specified date (string. SetDate () sets a day of the month in the Date object (1 ~ 31 ). SetMonth () sets the month (0 ~) in the Date object ~ 11 ). SetFullYear () sets the year (four digits) in the Date object ). Use the setFullYear () method instead of setYear. SetHours () sets the hour (0 ~) in the Date object ~ 23 ). SetMinutes () sets the minute (0 ~ 59 ). SetSeconds () sets the second (0 ~) in the Date object ~ 59 ). SetMilliseconds () sets the millisecond (0 ~) in the Date object ~ 999 ). SetTime () sets the Date object in milliseconds. SetUTCDate () sets the day of the month in the Date object based on the Universal Time (1 ~ 31 ). SetUTCMonth () sets the month (0 ~ 11 ). SetUTCFullYear () sets the year (four digits) in the Date object based on the universal time ). SetUTCHours () sets the hour (0 ~ 23 ). SetUTCMinutes () sets the minute (0 ~ 59 ). SetUTCSeconds () sets the second (0 ~) in the Date object based on the universal time ~ 59 ). SetUTCMilliseconds () sets the millisecond (0 ~ 999 ). ToSource () returns the source code of the object. ToString () converts a Date object to a string. ToTimeString () converts the time part of the Date object to a string. ToDateString () converts the Date part of the Date object to a string. Use the toUTCString () method instead of toGMTString. ToUTCString () converts a Date object to a string based on the universal time. ToLocaleString () converts a Date object to a string based on the local time format. ToLocaleTimeString () converts the time part of the Date object to a string based on the local time format. ToLocaleDateString () converts the Date part of the Date object to a string based on the local time format. UTC () returns the number of milliseconds from January 1, January 1, 1970 to the specified date based on the universal time. ValueOf () returns the original value of the Date object.
These are references: w3school (http://www.w3school.com.cn/jsref/jsref_obj_date.asp)

You can use it directly if needed ~~

Here is another function I wrote to determine whether it is a leap year:

function getBoolYear (Year) {var BoolYear;if ((Year%400 == 0 || (Year%100 != 0 && Year%4 == 0))) {BoolYear = true;}else{BoolYear = false;}return BoolYear;}
You can also know how many days a month is based on whether it is a leap year. The function is as follows:

function getMonthDay (Month, BoolYear) {var MonthDay;switch(Month){case 1:case 3:case 5:case 7:case 8:case 10:case 12:MonthDay = 31;break;case 4:case 6:case 9:case 10:case 11:MonthDay = 30;break;case 2:if (BoolYear == true) {MonthDay = 29;break;}else{MonthDay = 28;break;}}return MonthDay;}

That's all about it ~~


How to Learn javascript?

Javascript (js) is the native code of jquery (jq), and jq is the js library.

[Jq is relatively simple, but I still think I should learn js first !] Put the books I recommended on your mobile phone. The next software that supports pdf will read the pdf tutorial on your mobile phone. Of course, you can also read the books on your computer .. When I use my computer, I insist on w3school reading and practicing... Focusing on persistence and practice + thinking...

Recommended books: [JavaScript entry classic (version 3rd)] directly download the attachment! (Javascript authoritative guide) is not suitable for beginners.

Recommended Website: www.w3school.com.cn/



How to Learn javascript?

Javascript (js) is the native code of jquery (jq), and jq is the js library.

[Jq is relatively simple, but I still think I should learn js first !] Put the books I recommended on your mobile phone. The next software that supports pdf will read the pdf tutorial on your mobile phone. Of course, you can also read the books on your computer .. When I use my computer, I insist on w3school reading and practicing... Focusing on persistence and practice + thinking...

Recommended books: [JavaScript entry classic (version 3rd)] directly download the attachment! (Javascript authoritative guide) is not suitable for beginners.

Recommended Website: www.w3school.com.cn/



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.