Convert a timestamp to a date format:
A simple line of code
var date = new Date (timestamp); Get a Time object note: If the timestamp is Uinx, remember to multiply at 1000.For example, PHP function time () to get the timestamp will be multiplied
/*----------Below is a way to get time and date, and what kind of format you need to stitch it up----------*/
Date.getfullyear ();//Get the full year (4-bit, 1970)
Date.getmonth ();//Get month (0-11, 0 for January, remember to add 1 when using)
Date.getdate ();//Acquisition Day (1-31)
Date.gettime ();//Get Time (number of milliseconds starting from 1970.1.1)
Date.gethours ();//acquisition of hours (0-23)
Date.getminutes ();//Get Minutes (0-59)
Date.getseconds ();//Get Seconds (0-59)
More useful ways to find this http://www.w3school.com.cn/jsref/jsref_obj_date.asp
Examples, such as the need for this format: YYYY-MM-DD hh:mm:ss
var date = new Date (1398250549490);
Y = 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 ();
Console.log (Y+m+d+h+m+s); Yes, hemp disc.
Output: 2014-04-23 18:55:49
Convert a date format to a timestamp:
It's simple, too.
Date = new Date (' 2014-04-23 18:55:49:123 '); Pass in a time format, if not passed is to get the current time, it is so simple.
There are three ways of getting
time1 = Date.gettime ()
Time2 = date.valueof ()
Time3 = Date.parse (Date)
Three ways to get the difference
First, second: accurate to milliseconds
The third type: only accurate to the second, milliseconds will be replaced by the
For example, the result of the above code output (the difference can be seen at one glance):
1398250549123
1398250549123
1398250549000
JS timestamp how to turn into a date format