Chào các bạn, minh đang tìm hiểu và làm quen với php
mình muốn lấy thời gian GMT ma viết bằng php có dang như sau:
Hôm nay: Thứ ba, 23 Tháng 03 2010, 10:05:05am
có bạn nào bít thì chỉ giúp mình với, mình cám ơn nhiều lắm lắm .
Mình có tìm hiểu được một đoan code lấy thời gian như sau :
<?php
function uptime()
{
// reference from http://www.xenocafe.com/tutorials/ph...dows/index.php
$result = false;
// windows ?
if (strpos(PHP_OS,'WIN') !== false)
{
$winstats = @shell_exec("net statistics server");
if ($winstats)
{
preg_match("(\d{1,2}/\d{1,2}/\d{4}\s+\d{1,2}\:\d{2}\s+\w{2})", $winstats, $matches);
$result = time() - strtotime($matches[0]);
}
}
else // linux ?
{
$uptime = @exec("cat /proc/uptime");
if ($uptime)
{
$uptime = split(" ",$uptime);
$result = $uptime[0];
}
}
return $result;
}
function format_uptime($seconds) {
$secs = intval($seconds % 60);
$mins = intval($seconds / 60 % 60);
$hours = intval($seconds / 3600 % 24);
$days = intval($seconds / 86400);
if ($days > 0) {
$uptimeString .= $days;
$uptimeString .= (($days == 1) ? " day" : " days");
}
if ($hours > 0) {
$uptimeString .= (($days > 0) ? ", " : "") . $hours;
$uptimeString .= (($hours == 1) ? " hour" : " hours");
}
if ($mins > 0) {
$uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins;
$uptimeString .= (($mins == 1) ? " minute" : " minutes");
}
if ($secs > 0) {
$uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " : "") . $secs;
$uptimeString .= (($secs == 1) ? " second" : " seconds");
}
return $uptimeString;
}
$uptime = uptime();
$uptimeString = format_uptime($uptime);
echo "Server uptime : $uptimeString";
?>
kết quả là : 14691 days, 3 hours, 22 minutes, 12 seconds
không bít cách nào để bit la thứ mấy, tháng mấy.Mong các bạn giúp đỡ thêm
Bookmarks