1. DateTime Conversion to timestamp
Strdate = "2015-08-09 08:01:36:789var d = new Date (strdate); var timestamp=Math.Round(d.GetTime());d ocument.write ("Timestamp:" +timestamp+ "<br>"); output:Timestamp:1439078496789
Other methods:var timestamp = Date. Parse (strdate);orvar timestamp = d.valueOf();Note:strdate to add milliseconds, or convert to DateTime will miss milliseconds.
2. Timestamp converted to datetime
functiontimestamp2string(time) {var datetime = new Date (); Datetime.settime (time); var year = Datetime.getfullyear (); var month = Datetime.getmonth () + 1; var date = Datetime.getdate (); var hour = datetime.gethours (); var minute = Datetime.getminutes (); var second = Datetime.getseconds (); var mseconds = Datetime.getmilliseconds (); Return year + "-" + month + "-" + date+ "" +hour+ ":" +minute+ ":" +second+ "." +mseconds;}; var time = "1439078496789"; or time=1439018115000; As a result, var strdate2 = timestamp2string (time);d ocument.write ("Date:" +strdate2+ "<br>"), Output:Date:2015-8-9 8:1:36.789
Copyright NOTICE: This article for Bo Master original article, welcome reprint, reproduced please indicate the source.
The conversion between JS timestamp and datetime