|
|
|
function timestamp ใครรู้บอกหน่อยค้า วิธีการใช้ timestamp เพื่อหาว่า ใช้เวลาเท่าไหร่ในการเข้าระบบ |
|
|
|
|
|
|
|
function calc_tl($t, $sT = 0, $sel = 'Y') {
$sY = 31536000;
$sW = 604800;
$sD = 86400;
$sH = 3600;
$sM = 60;
if($sT) {
$t = ($sT - $t);
}
if($t <= 0) {
$t = 0;
}
$bs[1] = ('1'^'9'); /* Backspace */
switch(strtolower($sel)) {
case 'y':
$y = ((int)($t / $sY));
$t = ($t - ($y * $sY));
$r['string'] .= "{$y} years{$bs[$y]} ";
$r['years'] = $y;
case 'w':
$w = ((int)($t / $sW));
$t = ($t - ($w * $sW));
$r['string'] .= "{$w} weeks{$bs[$w]} ";
$r['weeks'] = $w;
case 'd':
$d = ((int)($t / $sD));
$t = ($t - ($d * $sD));
$r['string'] .= "{$d} days{$bs[$d]} ";
$r['days'] = $d;
case 'h':
$h = ((int)($t / $sH));
$t = ($t - ($h * $sH));
$r['string'] .= "{$h} hours{$bs[$h]} ";
$r['hours'] = $h;
case 'm':
$m = ((int)($t / $sM));
$t = ($t - ($m * $sM));
$r['string'] .= "{$m} minutes{$bs[$m]} ";
$r['minutes'] = $m;
case 's':
$s = $t;
$r['string'] .= "{$s} seconds{$bs[$s]} ";
$r['seconds'] = $s;
break;
default:
return calc_tl($t);
break;
}
return $r;
}
ตัวอย่าง วิธีการใช้
$startTime = time(); // เวลาเริ่มต้น
$stopTime = mktime(23,59,59,12,31,2011); // เวลาสิ้นสุด
$tY = calc_tl($startTime, $stopTime, 'Y');
print_r($tY);
ผลลัพ
Array
(
[string] => 4 years 35 weeks 6 days 4 hours 54 minutes 33 seconds
[years] => 4
[weeks] => 35
[days] => 6
[hours] => 4
[minutes] => 54
[seconds] => 33
)
|
|
|
|
|
Date :
19 เม.ย. 2551 11:46:56 |
By :
siriwat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากนะค่ะ แต่ว่า เอาไปใช้ไงหง่า ไม่รู้จริง ๆ
|
|
|
|
|
Date :
19 เม.ย. 2551 12:36:17 |
By :
ashichirokano |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองได้แล้วนะค่ะ แต่ว่า อืมมันไม่ใช่แบบที่ต้องการอ่ะค่ะ แบบว่า google มันจะขึ้นว่าเราใช้เวลาในการค้นหาคำนี้
กี่วินาที
ส่วนที่ระบบต้องการคือ ให้มันแสดงว่าใช้เวลากี่วินาทีในการเข้าระบบ
|
|
|
|
|
Date :
19 เม.ย. 2551 12:41:02 |
By :
asahichirokano |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|