var mydate = new Date ();
Mydate.getyear (); Get Current year (2-bit)
Mydate.getfullyear (); Get the full year (4-bit, 1970-????)
Mydate.getmonth (); Get the current month (0-11, 0 for January)//So get the current month is mydate.getmonth () +1;
Mydate.getdate (); Get current day (1-31)
Mydate.getday (); Get Current week x (0-6, 0 for Sunday)
Mydate.gettime (); Gets the current time (the number of milliseconds since 1970.1.1)
Mydate.gethours (); Get current number of hours (0-23)
Mydate.getminutes (); Gets the current number of minutes (0-59)
Mydate.getseconds (); Gets the current number of seconds (0-59)
Mydate.getmilliseconds (); Gets the current number of milliseconds (0-999)
Mydate.tolocaledatestring (); Get Current date
var mytime=mydate.tolocaletimestring (); Get current time
Mydate.tolocalestring (); Get Date and time
==========================================================================
JS Gets the current timestamp method-javascript Gets the current millisecond timestamp in the following three ways:
var timestamp =date.parse (New Date ()); Results: 1280977330000//Not recommended; Milliseconds changed to 000 display.
var timestamp = (new Date ()). ValueOf (); Results: 1280977330748//recommended;
var timestamp=new Date (). GetTime (); Results: 1280977330748//recommended;
JS in separate call to New Date (); Show this format Mar 10:10:43 utc+0800 2012
But participating in the calculation with the new Date () is automatically converted to the number of milliseconds starting from 1970.1.1
--------------------------------------------------------------------------------------------------
Convert a date in string form to a Date object
var strtime= "2011-04-16"; String date format
var date= new Date (Date.parse (Strtime.replace (/-/g, "/")); Convert to data ();
--------------------------------------------------------------------------------------------------
New Date (); The argument can be an integer; can also be a string; But the format must be correct
New Date (2009,1,1); That's right
New Date ("2009/1/1"); That's right
New Date ("2009-1-1"); Error
New Date (year, month, Date, hrs, min, sec) Create a Date object by the given parameters
Parameter description:
The year value is: 1900 to be set. For example, the year that you want to set is 1997, and the value of years should be 97, which is the result of 1997-1900. So the date can be set to a minimum of 1900 years;
The range for month is 0~11,0 for January, with 11 tables representing December;
The range of date is between 1~31;
The value of hrs ranges between 0~23. From midnight to the next day 1 o'clock in the morning hrs=0, from noon to 1 o'clock in the afternoon between the hrs=12;
The value of min and SEC ranges between 0~59.
Example Date day=new date (11,3,4);
The time in day is: 04-apr-11 12:00:00 AM
In addition, incorrect parameters can be given.
The example set time is February 30, 1910 and it will be interpreted as March 2.
Date Day=new date (10,1,30,10,12,34);
System.out.println ("Day's date is:" +day);
Printed as: Day ' s date is:web Mar 10:13:34 gmt+08:00 1910
--------------------------------------------------------------------------------------------------
1. Current system locale format (tolocaledatestring and tolocaletimestring)
Example: (new Date ()). toLocaleDateString () + "" + (new Date ()). toLocaleTimeString ()
Results: January 29, 2008 16:13:11
2. Ordinary strings (todatestring and toTimeString)
Example: (new Date ()). toDateString () + "" + (new Date ()). toTimeString ()
Results: Tue Jan 16:13:11 utc+0800
3. Greenwich Mean Time (togmtstring)
Example: (New Date ()). toGMTString ()
Results: Tue, Jan 08:13:11 UTC
4. Global Standard Time (toutcstring)
Example: (New Date ()). toUTCString ()
Results: Tue, Jan 08:13:11 UTC
5.Date Object String (toString)
Example: (New Date ()). ToString ()
Results: Tue Jan 16:13:11 utc+0800 2008
--------------------------------------------------------------------------------------------------
A Date object can also be used to compare two dates.
var mydate=new Date (); Mydate.setfullyear (2008,7,9); var today = new Date (); if (mydate>today) {...; }
New Date () related content