Transferred from: http://wyoojune.blog.163.com/blog/static/57093325201131193650725/
This in Php+mssql (date type datetime) +ajax when the ability to use, JS need to convert the timestamp to a normal format, the general situation may not be used
<script> function Getlocaltime (ns) { return new Date (parseint (NS) *). toLocaleString (). Replace (/:\ d{1,2}$/, '); } Alert (Getlocaltime (1293072805));
Pop-up: December 23, 2010 10:53
can also be used:
<script> function Getlocaltime (ns) { return new Date (parseint (NS) *). toLocaleString (). substr (0,17 )} Alert (Getlocaltime (1293072805)); </script>
Suppose you want to pop up: 2010-10-20 10:00:00 This format is good
<script> function Getlocaltime (ns) { return new Date (parseint (NS) *). toLocaleString (). Replace (/year | Month/g, "-"). Replace (/day/g, ""); } Alert (Getlocaltime (1177824835)); </script>
I also refer to some of the other web sites, such as the following:
function FormatDate (now) { var year=now.getyear (); var month=now.getmonth () +1; var date=now.getdate (); var hour=now.gethours (); var minute=now.getminutes (); var second=now.getseconds (); return year+ "-" +month+ "-" +date+ " " +hour+ ":" +minute+ ":" +second; } var d=new Date (1230999938); Alert (FormatDate (d));
The special mention is:
The numbers from MySQL could be strings, and the numbers would have to be *1000, because JS is used in milliseconds!!!!! My example is the following:
var time_num = $ ("date", message). text (); var time_num = parseint (time_num); It comes back with a string var d = new Date (time_num*1000); This is very important to *1000 var temp_time = formatdate (d);
The first example is a fairly regular one, and everything is in the mood!
JS Timestamp converted to date format