jquery action on the current date (formatting the current date)

Source: Internet
Author: User

  1. An extension to date that converts date to a string of the specified format
  2. The month (m), Day (d), hour (h), Minute (m), second (s), quarter (q) can be used with 1-2 placeholders,
  3. Year (y) can use 1-4 placeholders, milliseconds (S) with only 1 placeholders (1-3 digits)
  4. Date.prototype.Format = function (FMT) { //author:meizz
  5. var o = {
  6. "m+": this.getmonth () + 1, //month
  7. "d+": this.getdate (), //day
  8. "H +": this.gethours (), //hour
  9. "m+": this.getminutes (), //min
  10. "s+": this.getseconds (), //sec
  11. "q+": Math.floor ((this.getmonth () + 3)/3), //quarterly
  12. "S": this.getmilliseconds () //MS
  13. };
  14. if (/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length));
  15. For (var k in O)
  16. if (new RegExp ("(" + K + ")"). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)?  (O[k]): (("xx" + o[k]). substr (("" + o[k]).));
  17. return FMT;
  18. }
  19. Call:
  20. var time1 = new Date ().  Format ("Yyyy-mm-dd");
  21. var time2 = new Date ().  Format ("Yyyy-mm-dd HH:mm:ss");
  22. var nowtime=New Date ();
  23. Nowtime.setmonth (Nowtime.getmonth ()-1);
  24. Alert (Nowtime.format ("Yyyy-mm-dd HH:mm:ss");)//Current time last month

jquery action on the current date (formatting the current date)

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.