Function timestamp2string (time) {var datetime = new date (); datetime. settime (time); var year = datetime. getfullyear (); var month = datetime. getmonth () + 1 <10? "0" + (datetime. getmonth () + 1): datetime. getmonth () + 1; var date = datetime. getdate () <10? "0" + datetime. getdate (): datetime. getdate (); var hour = datetime. gethours () <10? "0" + datetime. gethours (): datetime. gethours (); var minute = datetime. getminutes () <10? "0" + datetime. getminutes (): datetime. getminutes (); var second = datetime. getseconds () <10? "0" + datetime. getseconds (): datetime. getseconds (); return year + "-" + month + "-" + date + "" + hour + ":" + minute + ":" + second ;}
The time when the database is queried is timestamp, which is encapsulated into the JSON data format. When it is passed to the JSP page through Ajax, it is displayed directly without any processing.[Object object];
The timestamp time after JSON encapsulation is as follows:
"Createtime": {"date": 25, "day": 2, "hours": 0, "Minutes": 0, "month": 2, "Nanos ": 0, "seconds": 0, "Time": 1395676800000, "timezoneoffset":-480, "year": 114}
How can we correctly display it as we want? The following JSCode:
The parameter time is the value of the time attribute in timestamp.
The return format can be adjusted as needed.