1: | <?php |
2: | |
3: | namespace ngatngay; |
4: | |
5: | class date |
6: | { |
7: | public static function now() |
8: | { |
9: | return time(); |
10: | } |
11: | |
12: | public static function startDay($day) |
13: | { |
14: | return mktime(00, 00, 00, (int) date('n'), $day); |
15: | } |
16: | |
17: | public static function startMonth($month) |
18: | { |
19: | return mktime(00, 00, 00, $month); |
20: | } |
21: | |
22: | public static function startYear() |
23: | { |
24: | } |
25: | |
26: | public static function currentDay() |
27: | { |
28: | return date('d'); |
29: | } |
30: | |
31: | public static function currentMonth() |
32: | { |
33: | return date('m'); |
34: | } |
35: | |
36: | public static function currentYear() |
37: | { |
38: | return date('Y'); |
39: | } |
40: | |
41: | public static function displayAgo($time) |
42: | { |
43: | $time = intval($time); |
44: | $times = time() - $time; |
45: | |
46: | if ($times < 1) { |
47: | $t = 'Vừa xong'; |
48: | } elseif ($times < 60) { |
49: | $t = $times . ' giây trước'; |
50: | } elseif ($times < 3600) { |
51: | $t = round($times / 60) . ' phút trước'; |
52: | } elseif ($times < 86400) { |
53: | $t = round($times / 3600) . ' giờ trước'; |
54: | } elseif ($times < 2_592_000) { |
55: | $t = round($times / 86400) . ' ngày trước'; |
56: | } elseif ($times < 31_536_000) { |
57: | $t = round($times / 2_592_000) . ' tháng trước'; |
58: | } else { |
59: | $t = round($times / 31_536_000) . ' năm trước'; |
60: | } |
61: | |
62: | return $t; |
63: | } |
64: | } |
65: | |