動態網頁製作技術PHP處理時間的執行個體

來源:互聯網
上載者:User

<?
/**
* 轉換為UNIX時間戳記
*/
function gettime($d) {
if(is_numeric($d))
return $d;
else {
if(! is_string($d)) return 0;
if(ereg(":",$d)) {
$buf = split(" ",$d);
$year = split("[-/]",$buf[0]);
$hour = split(":",$buf[1]);
if(eregi("pm",$buf[2]))
$hour[0] = 12;
return mktime($hour[0],$hour[1],$hour[2],$year[1],$year[2],$year[0]);
}else {
$year = split("[-/]",$d);
return mktime(0,0,0,$year[1],$year[2],$year[0]);
}
}
}

/**
*
* DateAdd(interval,number,date)
* 返回已添加指定時間間隔的日期。
* Inetrval為表示要添加的時間間隔字串運算式,例如分或天
* number為表示要添加的時間間隔的個數的數值運算式
* Date表示日期
*
* Interval(時間間隔字串運算式)可以是以下任意值:
* yyyy year年
* q Quarter季度
* m Month月
* y Day of year一年的數
* d Day天
* w Weekday一周的天數
* ww Week of year周
* h Hour小時
* n Minute分
* s Second秒
* w、y和d的作用是完全一樣的,即在目前的日期上加一天,q加3個月,ww加7天。
*/
function DateAdd($interval, $number, $date) {
$date = gettime($date);
$date_time_array = getdate($date);
$hours = $date_time_array["hours"];
$minutes = $date_time_array["minutes"];
$seconds = $date_time_array["seconds"];
$month = $date_time_array["mon"];

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.