It is often seen that some video stations show a video, how many days ago, how many minutes ago, and how many years ago,
In fact, it is easy to implement. The following is a function:
<? PHP
Include_once ('timeago. php ');
$ Cur_time1 = "1291684422"; // UNIX time, unified use
Echo time_ago ($ cur_time1 );
?>
Timeago. php
<? PHP
Function time_ago ($ cur_time ){
$ Time _ = Time ()-$ cur_time;
$ Seconds = $ time _;
$ Minutes = round ($ time _/60 );
$ Hours = round ($ time _/ 3600 );
$ Days = round ($ time _/86400 );
$ Weeks = round ($ time _/ 604800 );
$ Months = round ($ time _/ 2419200 );
$ Years = round ($ time _/ 29030400 );
// Seconds
If ($ seconds <= 60 ){
$ Time = "$ seconds ago ";
// Minutes
} Else if ($ minutes <= 60 ){
If ($ minutes = 1 ){
$ Time = "one minute ago ";
} Else {
$ Time = "$ minutes Minutes Ago ";
}
// Hours
} Else if ($ hours <= 24 ){
If ($ hours = 1 ){
$ Time = "one hour ago ";
} Else {
$ Time = "$ hours ago ";
}
// Days
} Else if ($ days <= 7 ){
If ($ days = 1 ){
$ Time = "one day ago ";
} Else {
$ Time = "$ Days Ago ";
}
// Weeks
} Else if ($ weeks <= 4 ){
If ($ weeks = 1 ){
$ Time = "one week ago ";
} Else {
$ Time = "$ weeks Weeks Ago ";
}
// Months
} Else if ($ months <= 12 ){
If ($ months = 1 ){
$ Time = "one month ago ";
} Else {
$ Time = "$ months ago ";
}
// Years
} Else {
If ($ year = 1 ){
$ Time = "one year ago ";
} Else {
$ Time = "$ year Years Ago ";
}
}
Return $ time;
}
?>
Note: Due to the English and Chinese grammar habits, in Chinese, there is no plural representation on the first and second years, so the aboveCodeYou can use it by yourself.