Timestamp format conversion
functionJsondateformat (jsondate) {//JSON date format converted to normal format varJsondatestr = Jsondate.tostring ();//ToString () is used here to let the incoming value be a string type, in order to avoid an incoming data type that does not support the. Replace () method Try { varK = parseint (Jsondatestr.replace ("/date (", ""). Replace (")/", ""), 10); if(K < 0) return NULL; varDate =NewDate (parseint ("Jsondatestr.replace" ("/date"). Replace (")/", ""), 10)); varmonth = Date.getmonth () + 1 < 10? "0" + (date.getmonth () + 1): Date.getmonth () + 1; varDay = Date.getdate () < 10? "0" +date.getdate (): Date.getdate (); varHours = Date.gethours () < 10? "0" +date.gethours (): Date.gethours (); varminutes = Date.getminutes () < 10? "0" +date.getminutes (): Date.getminutes (); varseconds = Date.getseconds () < 10? "0" +date.getseconds (): Date.getseconds (); varmilliseconds =date.getmilliseconds (); returnDate.getfullyear () + "-" + month + "-" + Day + "" + Hours + ":" + minutes + ":" +seconds; } Catch(ex) {return"Time Format conversion error"; }}
Get Current time conversion
functionDatetimediff (diff) {varMyDate =NewDatetimeadd (' d ', diff); //get Current year varYear =mydate.getfullyear (); //Get Current Month varmonth = Mydate.getmonth () + 1; //Get current day varDate =mydate.getdate (); varh = mydate.gethours ();//gets the current number of hours (0-23) varm = Mydate.getminutes ();//gets the current number of minutes (0-59) vars =mydate.getseconds (); varnow = year + '-' + P (month) + "-" + p (date) + "" + P (H) + ': ' + P (m) + ":" +p (s); returnNow ;}/** * Get current time*/functionp (s) {returnS < 10? ' 0 ' +s:s;}functionDatetimeadd (strinterval, number) {varDttmp =NewDate (); Switch(strinterval) { Case' s ':return NewDate (Date.parse (dttmp) + (1000 *Number )); Case' N ':return NewDate (Date.parse (dttmp) + (60000 *Number )); Case' H ':return NewDate (Date.parse (dttmp) + (3600000 *Number )); Case' d ':return NewDate (Date.parse (dttmp) + (86400000 *Number )); Case' W ':return NewDate (Date.parse (dttmp) + ((86400000 * 7) *Number )); Case' Q ':return NewDate (Dttmp.getfullyear (), (Dttmp.getmonth ()) + number * 3, Dttmp.getdate (), dttmp.gethours (), Dttmp.getminutes (), dttmp.getseconds ()); Case' m ':return NewDate (Dttmp.getfullyear (), (Dttmp.getmonth ()) +Number , Dttmp.getdate (), dttmp.gethours (), Dttmp.getminutes (), dttmp.getseconds ()); Case' Y ':return NewDate ((dttmp.getfullyear () +Number ), Dttmp.getmonth (), Dttmp.getdate (), dttmp.gethours (), Dttmp.getminutes (), dttmp.getseconds ()); }}
Getting Started with web front-end programming--js time Conversion