JS get current date: JS get current date time and other actions

Source: Internet
Author: User
Tags date format current time string tostring

var mydate = new Date ();
Mydate.getyear (); Get Current year (2-bit)
Mydate.getfullyear (); Get full year (4-bit, 1970-????)
Mydate.getmonth (); Get Current month (0-11, 0 for January)
Mydate.getdate (); Get the current day (1-31)
Mydate.getday (); Get Current week x (0-6, 0 for Sunday)
Mydate.gettime (); Gets the current time (number of milliseconds since 1970.1.1)
Mydate.gethours (); Get the current number of hours (0-23)
Mydate.getminutes (); Get the current number of minutes (0-59)
Mydate.getseconds (); Get the current number of seconds (0-59)
Mydate.getmilliseconds (); Get current number of milliseconds (0-999)
Mydate.tolocaledatestring (); Get Current date
var mytime=mydate.tolocaletimestring (); Get current time
Mydate.tolocalestring (); Get Date and time
Date Time Script Library method list
Date.prototype.isleapyear Judge Leap Year
Date.prototype.format Date format
Date.prototype.dateadd Date Calculation
Date.prototype.datediff Comparison Date Difference
Date.prototype.tostring Date-turn string
Date.prototype.toarray date split into arrays
Date.prototype.datepart some information about the date
Date.prototype.maxdayofdate the maximum number of days of the month from which the date is taken
Date.prototype.weeknumofyear the first weeks of the year in which the date is judged
Stringtodate String Turn Date type
Isvaliddate Validation Date Validity
Checkdatetime Full Date Time check
Daysbetween Date Days Bad
//---------------------------------------------------
Judging leap years
//---------------------------------------------------
Date.prototype.isleapyear = function ()
{
Return (0==this.getyear ()%4&& (This.getyear () 0!=0) (This.getyear () @0==0));
}
//---------------------------------------------------
Date formatting
Format Yyyy/yyyy/yy/yy represents year
Mm/m Month
W/W Week
dd/dd/d/d Date
hh/hh/h/h time
mm/m minutes
SS/SS/S/S seconds
//---------------------------------------------------
Date.prototype.format = function (FORMATSTR)
{
var str = FORMATSTR;
var week = [' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six '];
Str=str.replace (/yyyyyyyy/,this.getfullyear ());
Str=str.replace (/yyyy/, (this.getyear ()%) >9? ( This.getyear ()%). ToString (): ' 0 ' + (this.getyear ()% 100)); This article links http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20120605/28271.html

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.