㈠ php 怎麼計算當前小時還剩餘多少分鍾
將需要計算的兩個時間轉換成時間戳
,php的時間戳就是以秒為單位計算的,兩個時間戳相減的結果就是相差的秒數咯
㈡ php當前時間夾30分鍾
<?php
/*
* author: china_skag
* time: 2014-07-08
* 發博時間計算(年,月,日,時,分,秒)
* $createtime 可以是當前時間
* $gettime 你要傳進來的時間
*/
class Mygettime{
function __construct($createtime,$gettime) {
$this->createtime = $createtime;
$this->gettime = $gettime;
}
function getSeconds()
{
return $this->createtime-$this->gettime;
}
function getMinutes()
{
return ($this->createtime-$this->gettime)/(60);
}
function getHours()
{
return ($this->createtime-$this->gettime)/(60*60);
}
function getDay()
{
return ($this->createtime-$this->gettime)/(60*60*24);
}
function getMonth()
{
return ($this->createtime-$this->gettime)/(60*60*24*30);
}
function getYear()
{
return ($this->createtime-$this->gettime)/(60*60*24*30*12);
}
function index()
{
if($this->getYear() > 1)
{
if($this->getYear() > 2)
{
return date("Y-m-d",$this->gettime);
exit();
}
return intval($this->getYear())." 年前";
exit();
}
if($this->getMonth() > 1)
{
return intval($this->getMonth())." 月前";
exit();
}
if($this->getDay() > 1)
{
return intval($this->getDay())." 天前";
exit();
}
if($this->getHours() > 1)
{
return intval($this->getHours())." 小時前";
exit();
}
if($this->getMinutes() > 1)
{
return intval($this->getMinutes())." 分鍾前";
exit();
}
if($this->getSeconds() > 1)
{
return intval($this->getSeconds()-1)." 秒前";
exit();
}
}
}
//類的使用實例
/*
*
* 調用類輸出方式
*
* $a = new Mygettime(time(),strtotime('-25 month'));
* echo iconv('utf-8', 'gb2312', $a->index())?iconv('utf-8', 'gb2312', $a->index()):iconv('utf-8', 'gb2312', '當前');
*
*/
㈢ php中如何獲得當前時間
一、使用函式 date() 實現
在編輯器中輸入<?php echo $showtime=date("Y-m-d H:i:s");?>,點擊回車就可以得知當前的時間。其中Y是代表4位的年份,H是24小時制,i 是分鍾,如: "00" 至 "59" 。s -是秒,如: "00" 至 "59" 。
d 是幾日,二位數字,若不足二位則前面補零。 如: "01" 至 "31" 。m代表月份,二位數字,若不足二位則在前面補零,如: "01" 至 "12" 。
二、使用time函數
在編輯器中輸入echo date("y-m-d",$time)點擊回車就可以得知當前的時間,其中Y是代表4位的年份,m代表月份,二位數字,若不足二位則在前面補零,如: "01" 至 "12" 。d 是幾日,二位數字,若不足二位則前面補零。 如: "01" 至 "31" 。
三、使用strftime函數
在編輯器中輸入echo strftime ("%hh%m %a %d %b" ,time());點擊回車就可以得知當前的時間。
(3)php當前時間加分鍾擴展閱讀:
Date/Time 函數
一、time — 返回當前的 Unix 時間戳
二、timezone_abbreviations_list — 別名 DateTimeZone::listAbbreviations
三、timezone_identifiers_list — 別名 DateTimeZone::listIdentifiers
四、timezone_location_get — 別名 DateTimeZone::getLocation
五、date — 格式化一個本地時間/日期
六、getdate — 取得日期/時間信息
七、gettimeofday — 取得當前時間
八、gmdate — 格式化一個 GMT/UTC 日期/時間
九、gmmktime — 取得 GMT 日期的 UNIX 時間戳
㈣ php 時間相加
$a=time();//獲取當前時間戳
$b=strtotime("+7days",$a);//獲取在以$a時間戳為基礎的七天後的時間戳
//注意,以上獲取的都是時間戳,strtotime()也要用時間戳,若想轉轉為閣下下用的那種顯示方式,應該再用date函數轉換
echodate("Y-m-d",$a);
echo"</br>";
echodate("Y-m-d",$b);
㈤ PHP怎麼獲取當前時間
要設置時區,PHP默認的不是中國的時區,是格林威治時間。所以設置一下時區就可以搞定!<?php
date_default_timezone_set('Etc/GMT-8'); //這里設置了時區
echo date("Y-m-d H:i:s");
?>
㈥ php 時間加減
<?php
echo "今天:",date('Y-m-d H:i:s'),"<br>";
echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));
?>
上一行輸出當前時間,下一行輸出明天時間
這里+1 day
可以修改參數1為任何想需要的數 day也可以改成year(年),month(月),hour(小時),minute(分),second(秒)
如
date('Y-m-d H:i:s',strtotime("+1 day +1 hour +1 minute");
可以隨便自由組合,以達到任意輸出時間的目的
註:該方法之針對1970年以後試用,也就是時間戳的適用范圍。
php 常用日期相函數[日期加減,兩日期之差,日期轉換時間截]
下面這些代碼是一些常用的日期處理函數了,可以兩個時間的日期加減,兩日期之差,日期轉換時間截等。
echo date('Y-m-d',strtotime('+1 d',strtotime('2009-07-08')));//日期天數相加函數
echo date("Y-m-d",'1246982400');
echo '<br>';
echo date("Y-m-d",'1279123200');
die();
$d = "2009-07-08 10:19:00";
echo date("Y-m-d",strtotime("$d +1 day")); //日期天數相加函數
function dateToTime($d)//把日期轉換成時間堆截
{
$year=((int)substr("$d",0,4));//取得年份
$month=((int)substr("$d",5,2));//取得月份
$day=((int)substr("$d",8,2));//取得幾號
return mktime(0,0,0,$month,$day,$year);
}
/*
下面函數計算兩日期之差
*/
$Date_1="2009-07-08";
echo $Date_1+1;
$Date_2="2009-06-08";
$Date_List_a1=explode("-",$Date_1);
$Date_List_a2=explode("-",$Date_2);
$d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]);
$d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);
$Days=round(($d1-$d2)/3600/24);
echo "兩日期之前相差有$Days 天";
㈦ php按時分時間段判斷語句
臨時寫了一段,你看看,
<?php
date_default_timezone_set('PRC');//設置時區,其中PRC為「中華人民共和國」
$j=date("H:i");獲得當前小時和分鍾的時間
$h=strtotime($j);//獲得當前小時和分鍾的時間時間戳
$z=strtotime('00:00');//獲得指定分鍾時間戳,00:00
$x=strtotime('00:29');//獲得指定分鍾時間戳,00:29
if($h>$z&&$z<$x){
echo'顯示時間是00:00到00:29分之間';
}
?>
㈧ PHP 時間 加上 時 分 秒
$S=rand(0,23);//隨機--時
$F=rand(0,59);//隨機--分
$M=rand(0,59);//隨機--秒
$coupon_start_time=strtotime(date('Y-m-d')."$S:$F:$M");//給這個上加上「$S,$F,$M」
$coupon_end_time=strtotime(date('Y-m-d',strtotime('+30day'))."$S:$F:$M");//給這個也上加上「$S,$F,$M」
㈨ 求一個簡單的php時間變數
functiont(){
date_default_timezone_set('Asia/Shanghai');
$h=date('H',$_SERVER['REQUEST_TIME']);
$m=date('i',$_SERVER['REQUEST_TIME']);
return$h.'-'.(strlen($m)>1?substr($m,0,1):'0');
}
如果分鍾不足10分鍾,返回的是0
時區設置的是上海的,你可以根據需求自己改
㈩ php 如何對time類型的時間進行加減如11:20:30加20分鍾
把這個時間轉換成時間戳,然後把20分鍾換算成秒數,然後與時間戳相加,再用函數把新得到的時間戳轉換成時間