Four constructor overloading methods. ----What are method overloads??
Constructors-First overloaded method: Basic Current time
Date = new Date (); Returns a Time object to invoke GetDate (), with the contents of the current time console.log (date); Thu Sep 14:01:53 gmt+0800 (China standard Time) date = date (); The return time string does not have a GetDate Date object method, the content is the current time console.log (date); Thu Sep 14:01:53 gmt+0800 (Chinese standard time) date = +new date (); Returns the time MS number Console.log (date);//A static method returns the current time with the 1970-01-01 interval, the millisecond unit Console.log (' static method ') Console.log (Date.now ()); 1443085759316
Constructors-second overload-passing millisecond values
The number of milliseconds from the start time of January 1, 1970, date = new Date (1238129999999), Console.log (Date.tolocalestring ()); March 27, 2015 12:59:59
Constructors-the third overload-passes scattered date-time parameters such as month-day time
/* Scattered time numeric constructors - constructors have 2-7 parameters, will be based on "year, month, day, hour, minute, second, millisecond" settling time */date = new Date (2015, 2, 27, 12, 59, 59); Console.log (Date.tolocalestring ()); March 27, 2015 12:59:59date = new Date (2, +, N), Console.log (Date.tolocalestring ()); March 27, 2015 12:59:00date = new Date (2, +); Console.log (date.tolocalestring ()); March 27, 2015 12:00:00date = new Date (2, +); Console.log (date.tolocalestring ()); March 27, 2015 0:00:00date = new Date (2); Console.log (date.tolocalestring ()); March 1, 2015 0:00:00
Constructors-fourth overload-passing a string in a date form
Date = new Date ("Month dd,yyyy hh:mm:ss"),//date = new Date (YYYY,MTH,DD),//month: month name in English, from January to december//mth: Represents the month in integers, from (January) to 11 (December)//dd: Represents the day of the one month, from 1 to 31//yyyy: four-digit year//HH: Hours, from 0 (midnight) to 23 (11 o'clock in the evening)//MM: number of minutes, integers from 0 to 59//ss: number of seconds, Integer from 0 to 59 date = new Date (' 2014/12/25 '); YYYY/MM/DD format console.log (date); 2014/12/25 00:00:00date = new Date (' 2014/12/25 12:00:00 '); YYYY/MM/DD HH:mm:ss format console.log (date); 2014/12/25 12:00:00date = new Date (' 2014-12-25 '); YYYY-MM-DD format console.log (date); 2014-12-25 08:00:00date = new Date (' 2014-12-25 12:00:00 '); YYYY-MM-DD HH:mm:ssconsole.log (date); 2014-12-25 12:00:00date = new Date ("December 31, 2015 23:59:59"); Month dd,yyyy hh:mm:ss format console.log (date); Thu Dec 23:59:59console.log (date.tolocalestring ()); 2015/12/31 pm 11:59:59date = New Date ("January 12,2015"); Month dd,yyyy format console.log (date)//mon Jan 00:00:00console.log (date.tolocalestring ()); 2015/1/12 12:00:00
Convert a Date object to a string
Convert cost to format--intelligently identify operating system language settings or browser language settings Console.log (' Convert to local format ') date = new Date (); Console.log (Date.tostring ()) // Convert to String Console.log (Date.tolocaletimestring ()) //Get current time pm 5:09:19console.log ( Date.tolocaledatestring ()) //Get current date 2015/9/24console.log (date.tolocalestring ()) //Get current Date and time 2015/9/24 5:09:19
Converts a string to a Date object's notation
Why do I need to convert it to a Date object: Because I need to get the date, or set the date time and so on the object's basis
Method 1 Constructor Overloading 4
var str = "2015-12-12";d ate = new Date (str); The string is converted to a Date object Console.log (Date.tolocalestring ()); 2015/12/12 8:00:00
Method 2 Date.parse
Converts the string to a Date object//And then returns the millisecond value between this Date object and ' 1970/01/01 00:00:00 ' (The time zone in Beijing is East 8, and the start time is actually: ' 1970/01/01 08:00:00 ') date = Date.parse ("Jul 8, 2005") Console.log (date) date = "2015-12-30"; console.log (date);//After wrapping the string as an object, We can use the properties and methods that the next object has ... Console.log ("<br/>" + da.getfullyear () + "-" + da.getmonth () + "-" + da.getdate ());
Get a specific date or time
When a Date object is instantiated using a constructor, we can then get the exact date, time, and so on from the various numbers
Get date- year (1970-???? ) month (0-11) Day (0-31) week (0-6) console.log (' Get date ') Date = new Date (); Console.log (Date.getfullyear ()) //Get full year (4 bits, 1970- ????) Console.log (Date.getyear ()) //Get Current year (2-bit, inaccurate, retired) starting with ECMAScript v3, JavaScript implementations no longer use this method, and getFullYear () Method instead Console.log (Date.getmonth ()) //Get the current month (0-11, 0 for January) console.log (Date.getdate ()); Get what -0-31 such as 25console.log (Date.getday ()); //Get Day of the week-such as 3//of the Week 3 Get time-hours (0-23) minutes (0-59) seconds (0-659) milliseconds (0-999) For example: 12:23:45 375console.log (' Get Time ') Date = new Date (), Console.log (Date.gethours ()) //Get hour 12console.log (Date.getminutes ()); Get Sub 23console.log (Date.getseconds ()); Gets the Seconds 45console.log (Date.getmilliseconds ()); Gets the millisecond 375console.log (Date.gettime ()); //Gets the millisecond value relative to 1970-01-01 1443085759313
Set a specific date or time
setFullYear (year, Opt_month, opt_date): Sets the age value of the date object; 4-bit year. Setmonth (Month, opt_date): Sets the month value of the Date object. 0 represents January, 11 represents December. SetDate (date): Sets the date value in the month of the date object; The range of the value 1~31. Sethours (Hour, opt_min, Opt_sec, opt_msec): Sets the hour value for the Date object. Setminutes (Min, Opt_sec, opt_msec): Sets the minute value of the Date object. Setseconds (sec, opt_msec): Sets the number of seconds for the date object. Setmilliseconds (msec): Sets the millisecond value of the Date object.
Object-oriented awareness js-built-in objects (emphasis)--date date objects