Requirements:Converts the time of the int type displayed on the first page to the time format of the date type:when Questionmodel gets to question list data, including question[' Pub_time '), it needs to be converted to a specific time format for display when it is displayed. when inserting a problem record, the Pub_time field uses the PHP time () function, gets the current timestamp integer, and then inserts it into the MySQL data table, so its format is int type.
However, when displayed in the HTML of view view, it needs to be formatted as a time format for display. But because each problem in order to facilitate pagination display data is through the JS splicing, so the function of conversion depends on JS.
search on the internet about JS to convert int to date format data is copied, and is not practical, so after reading the official PHP and JS Manual, learned that:
- Time () in PHP is the timestamp of the current UNIX, accurate to the number of seconds https://secure.php.net/manual/zh/function.time.php
- The new date () in JS can convert the int data to date type data by passing parameters to date, and the parameters are accurate to the number of milliseconds https://developer.mozilla.org/zh-CN/ Docs/web/javascript/reference/global_objects/date
Now the problem is very simple to convert, through the JS Date object to the corresponding month and day can be, by default, the value of the date variable is a time format string.
var Time // 1483970035 var Date New Date (time *1000); var Date. getFullYear (); var date. GetMonth () + 1; var Date. getDate = year + '-' + month + '-' + day;
The result of the implementation:
Really just the difference between the number of seconds and the number of milliseconds, after ignoring the confusion for a long time.
JS converts the time stamp generated by PHP into a date in a specific date format