-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimego.php
122 lines (53 loc) · 1.75 KB
/
timego.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
function timeago($stamp){
$ptime= strtotime($stamp);
$ctime =time();
$tdiff = $ctime - $ptime;
$sec = $tdiff;
$minutes= round($sec / 60 ); // value 60 sec
$hours= round($sec / 3600 ); //val 3600sec is 60 min
$days= round($sec / 86400 ); //=24 * 60 *60
$weeks= round($sec /604800 ); // 7 * 24 *60 * 60
$months = round($sec / 2629440 ); // ((365 + 365 +365 + 365+366)/5/12)*24*60*60
$years = round($sec / 31553280 );// (365 + 365 +365 + 365+366)/5*24*60*60
if($sec <= 60){
return " just now ";
}
else if ( $minutes <= 60){
if ($minutes == 1){
return "one min ago ";
}else {
return "$minutes mins ago";
}
}
else if ( $hours <= 24){
if ($hours == 1){
return "an hour ago ";
} else {
return "$hours hrs ago";
}
}
else if ( $days <= 7){
if ($days == 1){
return "yesterday "; }
else {
return "$days days ago";
}
}
else if ( $weeks <= 4.3){ //4,3 = 52/12
$datec = new DateTime($stamp);
$dfix=$datec ->format(" M d " ); ///date constraints
return $dfix;
}
else if ( $months <= 12){ //4,3 = 52/12
$datec = new DateTime($stamp);
$dfix=$datec ->format(" M d " ); ///date constraints
return $dfix;
}
else {
$datec = new DateTime($stamp);
$dfix=$datec ->format(" M d .Y " ); ///date constraints
return $dfix;
}
}
?>