How to get the date of the previous month through js Date range initialization _ javascript skills

Source: Internet
Author: User
This article describes how to initialize the js Date range to get the date of the previous month. it involves related techniques related to the date of javascript operations and is very useful, for more information about how to initialize the js date range, see the following example. Share it with you for your reference. The specific analysis is as follows:

The initialization of the time range is set today. The start time is the previous month of the current time, and the perfect solution is finally found.

Date.prototype.format = function(format) { var o = {  "M+" : this.getMonth() + 1, // month  "d+" : this.getDate(), // day  "h+" : this.getHours(), // hour  "m+" : this.getMinutes(), // minute  "s+" : this.getSeconds(), // second  "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter  "S" : this.getMilliseconds() // millisecond } if (/(y+)/.test(format))  format = format.replace(RegExp.$1, (this.getFullYear() + "")    .substr(4 - RegExp.$1.length)); for ( var k in o)  if (new RegExp("(" + k + ")").test(format))   format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]     : ("00" + o[k]).substr(("" + o[k]).length)); return format;}var begin=new Date();var end=new Date();new Date(begin.setMonth((new Date().getMonth()-1)));var begintime= begin.Format("yyyy-MM-dd");var endtime=end.Format("yyyy-MM-dd");$('#txtBeginVisitTime').val(begintime);$('#txtEndVisitTime').val(endtime);

I hope this article will help you design javascript programs.

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.