-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtime_functions.php
More file actions
109 lines (96 loc) · 1.73 KB
/
time_functions.php
File metadata and controls
109 lines (96 loc) · 1.73 KB
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
<?php
function min_to_hour_small($mins)
{
$hours = 0 ;
$minutes = $mins;
$message="";
if($mins>60)
{
$hours = (int) ($mins/60);
$minutes = $mins%60;
$message = $hours;
if($hours>1)
{
$message.=" h ";
}
else
{
$message.=" h ";
}
if($minutes>0)
{
$message .= $minutes. " m ";
}
}
else
{
if($minutes>0)
{
$message = $minutes. " m ";
}
}
return $message;
}
function min_to_hour($mins)
{
$hours = 0 ;
$minutes = $mins;
$message="";
if($mins>60)
{
$hours = (int) ($mins/60);
$minutes = $mins%60;
$message = $hours;
if($hours>1)
{
$message.=" hours ";
}
else
{
$message.=" hour ";
}
if($minutes>0)
{
$message .= $minutes. " minutes";
}
}
else
{
if($minutes>0)
{
$message = $minutes. " minutes";
}
}
return $message;
}
function timeago($date) {
$timestamp = strtotime($date);
$strTime = array("second", "minute", "hour", "day", "month", "year");
$length = array("60","60","24","30","12","10");
$currentTime = time();
if($currentTime >= $timestamp) {
$diff = time()- $timestamp;
for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) {
$diff = $diff / $length[$i];
}
$diff = round($diff);
return $diff . " " . $strTime[$i] . "(s) ago ";
}
}
function readableDate($date)
{
return date("F jS, Y", strtotime($date));
}
function readableDateTime($date)
{
return date("F j, Y, g:i a", strtotime($date));
}
function readableDateTime2($date)
{
return date("jS F Y g:i A", strtotime($date));
}
function readableTimeFromDAte($date)
{
return date("g:i A", strtotime($date));
}
?>