Here is a summary of the time stamp in JS and the date format of the mutual conversion:
1. Convert the timestamp to a date format:
functionTimestamptotime (timestamp) {varDate =NewDate (timestamp * 1000);//The timestamp is 10-bit *1000 and the timestamp is 13-bit, so you don't need to multiplyY = date.getfullyear () + '-'; M= (Date.getmonth () +1 < 10? ' 0 ' + (date.getmonth () +1): Date.getmonth () +1) + '-'; D= Date.getdate () + "; H= date.gethours () + ': '; M= date.getminutes () + ': '; S=date.getseconds (); returny+m+d+h+m+s; } timestamptotime (1403058804); Console.log (Timestamptotime (1403058804));//2014-06-18 10:33:24
Note: If it is a Unix timestamp, remember to multiply by 1000. For example: Php function time () Gets the timestamp multiplied by 1000.
2. Convert the date format to a timestamp:
var New Date (' 2014-04-23 18:55:49:123 '); // There are three ways of getting var time1 = date.gettime (); var time2 = date.valueof (); var time3 = date.parse (Date); Console.log (time1); // 1398250549123 Console.log (time2); // 1398250549123 Console.log (Time3); // 1398250549000
The difference between the above three methods of acquisition:
First, second: accurate to milliseconds
The third type: only accurate to seconds, milliseconds with 000 instead
The difference between the above three output results can be observed
Note: The time stamp obtained is divided by 1000 to obtain a UNIX timestamp, which can be passed to the background.
The conversion between JS timestamp and date format