Time format conversion question 22:26:56
How to convert the preceding time format to 3 seconds ago or 3 days ago
Reply to discussion (solution)
$ Time = '2017-11-01 22:26:56 '; echo date ('Y-m-d H: I: S', strtotime ($ time)-3 ); // echo 3 seconds ago"
"; Echo date ('Y-m-d H: I: S', strtotime ($ time)-3*24*60*60); // 3 days ago
function time_since($since) { $chunks = array( array(60 * 60 * 24 * 365 , 'year'), array(60 * 60 * 24 * 30 , 'month'), array(60 * 60 * 24 * 7, 'week'), array(60 * 60 * 24 , 'day'), array(60 * 60 , 'hour'), array(60 , 'minute'), array(1 , 'second') ); for ($i = 0, $j = count($chunks); $i < $j; $i++) { $seconds = $chunks[$i][0]; $name = $chunks[$i][1]; if (($count = floor($since / $seconds)) != 0) { break; } } $print = ($count == 1) ? '1 '.$name : "$count {$name}s"; return $print;}
The code is as follows:
The time format displayed on the webpage is: 1382972373. how to convert the time format to three seconds ago or three days ago
This is more convenient and you don't need to change it:
$ Time = '000000'; echo date ('Y-m-d H: I: S', $ time-3); // echo 3 seconds ago"
"; Echo date ('Y-m-d H: I: S', $ time-3*24*60*60); // 3 days ago
If you want to display the timestamp in the result, you do not need to convert date:
$ Time = '000000'; echo $ time-3; // echo 3 seconds ago"
"; Echo $ time-3*24*60*60; // 3 days ago
[/Code]
The code is as follows:
The time format displayed on the webpage is: 1382972373. how to convert the time format to three seconds ago or three days ago
What do you mean is how many minutes ago weibo was published? You can use the function that I sent.
Yes, just like how many minutes ago the weibo app was released, how can it be called?