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.