Related operations for date functions in JavaScript

Source: Internet
Author: User
Tags timestamp to date

2016-08-03 11:41:10

New Date ()
New Date (milliseconds)
New Date (datestring)
New Date (year, month)
New Date (year, month, day)
New Date (year, month, day, hours)
New Date (year, month, day, hours, minutes)
New Date (year, month, day, hours, minutes, seconds)
New Date (year, month, day, hours, minutes, seconds, microseconds)

The following is for 1.new date (), when there are no parameters, the current time Date object is created. 2.new Date (milliseconds), when the argument is a number, then this parameter is the timestamp, which is treated as milliseconds, creating a time-date object that is specified in milliseconds from January 1, 1970. 3.new Date (datestring), this parameter is a string, and this string must be able to use the Date.parse () conversion.

3.new Date (datestring), this parameter is a string, and this string must be able to use the Date.parse () conversion.
4. The following six constructors are precisely defined:
1). Year, is an integer, if it is 0-99, then add 1900 on this basis, and the others are returned as-is.
2). Month, is an integer with a range of 0-11.
3). Day, is an integer with a range of 1-31.
4). Hours, is an integer with a range of 0-23.
5). Minutes, is an integer with a range of 0-59.
6). Seconds, is an integer with a range of 0-59.
7). Microseconds is an integer with a range of 0-9999.

1 <HTML>2     <Head>3     <title>Time stamp converted to month day</title>4     <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />    5     </Head>6     <Body>7     </Body>8 </HTML>9 <Script>Ten window.onload=function(){ One  A           var Now=NewDate ();//Current system Time -           varShijianchuo=now.gettime ();//gets the current time stamp - Alert ("time stamp:"+Shijianchuo); the           varnowdate= NewDate (Shijianchuo);//Convert a timestamp to a Date object -           varNowtime=nowdate. Format ("YYYY-MM-DD Hh:mm:ss");//formats the current system time, which is equivalent to converting the timestamp to date - Alert ("Current Time:"+nowtime); -  +      } -  +      A     /* at Date formatting: - An extension to date that converts date to a string of the specified format - the year (Y) can use 1-4 placeholders, and the quarter (Q) can be used with 1-2 placeholders. - 1-2 placeholders can be used for months (m), days (d), hours (h), minutes (m), seconds (s). - milliseconds (S) can only be used with 1 placeholders (1-3 digits) - Example: in (New Date ()). Format ("Yyyy-mm-dd hh:mm:ss. S ") - (New Date ()). Format ("Yyyy-mm-dd hh:mm:ss. s milliseconds QQ quarter ") to     */ + Date.prototype.Format= function(FMT) { -         varo= { the             "m+":  This. GetMonth ()+ 1, //Month *             "d+":  This. GetDate (),//Day $             "H +":  This. GetHours (),//whenPanax Notoginseng             "m+":  This. getminutes (),//points -             "s+":  This. getseconds (),//seconds the             "q+": Math.floor (( This. GetMonth ()+ 3) / 3), //Quarterly +             "S":  This. Getmilliseconds ()//milliseconds A         }; the         if (/(y+)/. Test (FMT) FMT=Fmt.replace (regexp.$1, ( This. getFullYear ()+ ""). substr (4 -regexp.$1. length)); +          for (varkincho) -         if (NewRegExp ("(" +k+ ")"). Test (FMT) FMT=Fmt.replace (regexp.$1, (regexp.$1. Length== 1) ?
(O[k]): (("xx" +o[k]). substr ("" +O[k] )); $ returnFMT; $ } - </Script>

Related operations for date functions in JavaScript

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.