-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.php
executable file
·70 lines (52 loc) · 1.43 KB
/
time.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
function timeAgo($time_ago){
$cur_time = time();
$time_elapsed = $cur_time - $time_ago;
$seconds = $time_ago;
$minutes = round($time_elapsed / 60);
$hours = round($time_elapsed / 3600);
$days = round($time_elapsed / 86400);
$weeks = round($time_elapsed / 604800);
$months = round($time_elapsed / 2600640);
$years = round($time_elapsed / 31207680);
if($seconds <=60 ){
echo "$seconds seconds ago";
}else if( $minutes <=60){
if ($minutes ==1){
echo "one minute ago";
}else {
echo "$minutes minutes ago";
}
}else if( $hours <=24){
if ($hours ==1){
echo "one hour ago";
}else {
echo "$hours hours ago";
}
}else if($days <=7){
if ($days ==1){
echo "one day ago";
}else {
echo "$days days ago";
}
}else if($weeks <=4.3){
if ($weeks ==1){
echo "one week ago";
}else {
echo "$weeks weeks ago";
}
}else if ($months <=12){
if ($months ==1){
echo "one month ago";
}else {
echo "$months months ago";
}
} else{
if ($years ==1){
echo "one year ago";
}else {
echo "$years years ago";
}
}
}
?>