JS format Time//"Yyyy-mm-dd hh:mm:ss" Date.prototype.format = function (format) {var Date = {"m+": this.getmonth () + 1, "d+": This.getdate (), "H +": this.gethours (), "m+": This.getminutes (), "s+": This.getsecond S (), "q+": Math.floor ((This.getmonth () + 3)/3), "S+": This.getmilliseconds ()}; if (/(y+)/i.test (format)) {format = Format.replace (regexp.$1, (this.getfullyear () + "). substr (4-regexp.$1.lengt h)); } for (var k in date) {if (New RegExp ("(" + K + ")"). Test (format)) {format = Format.replace (REGEXP. $ regexp.$1.length = = 1? Date[k]: ("XX" + date[k]). substr (("" + date[k]). length); }} return format;} Time plus days Date.prototype.addDays = function (day, format) {this.setdate (this.getdate () + date); return This.format (format);} Time plus weeks Date.prototype.addWeeks = function (w) {this.adddays (w * 7);};/ /time plus number of months Date.prototype.addMonths = function (m) {varD = this.getdate (); This.setmonth (This.getmonth () + M); if (This.getdate () < D) This.setdate (0);};/ /time plus number of years Date.prototype.addYears = function (y) {var m = this.getmonth (); This.setfullyear (This.getfullyear () + y); if (M < This.getmonth ()) {this.setdate (0); }};//based on date, up to week Date.prototype.getWeek = function () {return new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") [This.getday ()];} Get parameters such as: string ('? A=hello&b=world '), Window.location.search.parameter (' a '); String.prototype.parameter = function (name) {var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)"); var r = this.substr (1). Match (REG); if (r! = null) return unescape (r[2]); return null;}
JavaScript time function