Get the data from the database in the background we want the format to Be:
October 25, 2016 17:37 30 seconds or 2016/10/25 17:37:30
But what we get at the front desk is a number (timestamp, number of milliseconds):
1477386005
Timestamp conversion, The core method :
1477386005 is to get a timestamp from the background (note: Sometimes the timestamp is multiplied by 1000)
var unixtimestamp = new Date (1477386005*1000); commontime = unixtimestamp.tolocalestring ();
Alert (commontime);
The result is:
Rewrite the toLocaleString () method to change to any format:
Date.prototype.toLocaleString = function () { return this.getfullyear () + "year" + (this.getmonth () + 1) + "month" + this.getd Ate () + "day" + this.gethours () + "point" + this.getminutes () + "min" + this.getseconds () + "sec"; };
The result is:
Other formats:
Date.prototype.toLocaleString = function () { return this.getfullyear () + "/" + (this.getmonth () + 1) + "/" + this.getd Ate () + "/" + this.gethours () + ":" + this.getminutes () + ":" + this.getseconds (); };
The result is:
article reference: lemon Whirlwind Leg
links: time stamp conversion website W3school
Convert the timestamp (in Milliseconds) from the background to the desired date format with JS