This can be used when the Php+mssql (date type is datetime) +ajax, JS need to convert the timestamp to a normal format, the general situation may not be used
[PHP]View Plaincopy
- <script>
- function Getlocaltime (NS) {
- return new Date (parseint (NS) *). toLocaleString (). replace (/:\d{1,2}$/,");
- }
- Alert (Getlocaltime (1293072805));
- </script>
Pop-up: December 23, 2010 10:53
You can also use:
[PHP]View Plaincopy
- <script>
- function Getlocaltime (NS) {
- return new Date (parseint (NS) *). toLocaleString (). SUBSTR (0,17)}
- Alert (Getlocaltime (1293072805));
- </script>
If you want to pop up: 2010-10-20 10:00:00 This format is done
[PHP]View Plaincopy
- <script>
- function Getlocaltime (NS) {
- return new Date (parseint (NS) *). toLocaleString (). Replace (/year | month/g, "-"). Replace (/day/g, "");
- }
- Alert (Getlocaltime (1177824835));
- </script>
In addition, I also took a look at some of the other sites of the East, as follows:
[PHP]View Plaincopy
- 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!!!!! I have the following:
[PHP]View Plaincopy
- var time_num = $ ("date", message). text ();
- var time_num = parseint (time_num); //Pass back a string
- var d = new Date (time_num*1000); //This is important to *1000
- var temp_time = formatdate (d);
The first example is more regular, and what is the case?