Javascript:/*** Date Calculation class * @author [Lee] <[<www.dollarphp.com>]>* @param dur increments such as: +1day-5 year 6months* @param time pass in support grid Formula 1, y-m-d h:i:s 2, 1111111111* @return string such as: 2018-01-01 00:00:00*/function dateparse (time = False,dur) {this.getdate = Funct Ion () {var test_year =/(-)? \d+ (\s)? year (s)?/.exec (dur) var test_month =/(-)? \d+ (\s)? month (s)?/.exec (dur) var te St_day =/(-)? \d+ (\s)? Day (s)?/.exec (dur) var test_hour =/(-)? \d+ (\s)? Hour (s)?/.exec (dur) var test_minute =/(-)? \d+ (\s)? minute (s)?/.exec (dur) var test_second =/(-)? \d+ (\s)? second (s)?/.exec (dur) test_year = (!test_year)? 0:parseint ( Test_year[0]) Test_month = (!test_month)? 0:parseint (test_month[0]) Test_day = (!test_day)? 0:parseint (Test_day[0)) Test_hour = (!test_hour)? 0:parseint (test_hour[0]) Test_minute = (!test_minute)? 0:parseint (Test_minute[0]) Test_seco nd = (!test_second) 0:parseint (test_second[0]) var outtime if (time) {if ((typeof (time) = = ' string ') | | (Time instanceof String)) &&Amp (/^\d{4} (-\d{2} (-\d{2})?)? $/.test (time))) {outtime = new Date (time) outtime.setfullyear (parseint (Outtime.getfullyear ()) + test _year) Outtime.setmonth (parseint (Outtime.getmonth ()) + Test_month) outtime.setdate (parseint (outtime). GetDate ()) + Test_day) outtime.sethours (parseint (Outtime.gethours ()) + Test_hour) outtime.setminutes (parseint (Outtime.getminutes ()) + Test_minute) outtime.setseconds (parseint (Outtime.getseconds ()) + Test_second) var month = This.parsetime (parseint (Outtime.getutcmonth ()) +1) var date = This.parsetime (parseint (ou Ttime.getutcdate ())) var hour = This.parsetime (parseint (Outtime.getutchours ())) var minute = THIS.PA Rsetime (parseint (Outtime.getutcminutes ())) var second = This.parsetime (parseint (Outtime.getutcseconds ())) }else{outtime = new Date (time*1000) outtime.setfullyear (parseint (Outtime.getfullyear ()) +Test_year) Outtime.setmonth (parseint (Outtime.getmonth ()) + Test_month) outtime.setdate (parseint (Outt Ime.getdate ()) + Test_day) outtime.sethours (parseint (Outtime.gethours ()) + Test_hour) outtime.setmin Utes (parseint (Outtime.getminutes ()) + Test_minute) outtime.setseconds (parseint (Outtime.getseconds ()) + test_sec ond) var month = This.parsetime (parseint (Outtime.getmonth ()) +1) var date = This.parsetime (parseint (o Uttime.getdate ())) var hour = This.parsetime (parseint (Outtime.gethours ())) var minute = This.parseti Me (parseint (Outtime.getminutes ())) var second = This.parsetime (parseint (Outtime.getseconds ()))}}els e{outtime = new Date () outtime.setfullyear (parseint (Outtime.getfullyear ()) + test_year) Outtime.setm Onth (parseint (Outtime.getmonth ()) + Test_month) outtime.setdate (parseint (Outtime.getdate ()) + Test_day) Outt Ime.sethours (parseint (ouTtime.gethours ()) + Test_hour) outtime.setminutes (parseint (Outtime.getminutes ()) + Test_minute) Outtime.setS Econds (parseint (Outtime.getseconds ()) + Test_second) var month = This.parsetime (parseint (Outtime.getmonth ()) +1) var date = This.parsetime (parseint (Outtime.getdate ())) var hour = This.parsetime (parseint (Outtime.gethours ())) var minute = This.parsetime (parseint (Outtime.getminutes ())) var second = This.parsetime (parseint (outtime.get Seconds ())} var year = Outtime.getfullyear () var ret = year+ '-' +month+ '-' +date+ ' +hour+ ': ' +minute+ ': ' +second return ret}this.parsetime = function (input) {var ret if (input >= 0 && input < ten) {ret = ' 0 ' + Input}else{ret = input} return Ret}}var Date_parser = new Dateparse (' 2018-05-08 ', ' +3hour +2year-5months ') date = Date_parser.getdate () console.log (date)
Php:参见:date_add函数
Mysql:参见:DATE_ADD函数
JavaScript, PHP, and MySQL date calculation functions