太史亨
php日期格式轉(zhuǎn)換總結(jié):
<?php
//將當(dāng)前時(shí)間轉(zhuǎn)換成yyyy-mm-dd格式串,再轉(zhuǎn)換成日期格式,繞了一圈哈
echo strtotime(date('Y-m-d',time()).' 00:00:00');
//將GNU 日期輸入格式的字符轉(zhuǎn)換成時(shí)間
echo strtotime('now');
//標(biāo)準(zhǔn)的字符串轉(zhuǎn)換成時(shí)間
$t = '2012-9-10 15:18:06';
$time = strtotime($t);
//將時(shí)間轉(zhuǎn)換成日期字符yyyymmdd,再轉(zhuǎn)換成整型格式
$d = intval(date('Ymd',$time));
echo '付款時(shí)間:'.$d;
<?phpheader("Content-type: text/html; charset=utf-8"); $txDate = '2016-06-16';
$dateTime1 = strtotime($txDate); //int 1466028000 將英文文本日期時(shí)間解析為 Unix 時(shí)間戳:
$dateTime2= date("Y-m-d H:i:s",$dateTime1); //string '2016-06-16 00:00:00'
(length=19) Date() 函數(shù)把時(shí)間戳格式化為更易讀的日期和時(shí)間。
//拼接今日最后時(shí)間2016-06-16 23:59:59
$dateTime= date("Y-m-d H:i:s",strtotime(date("Y-m-d",strtotime($dateTime2))."+ 23 hours 59 minutes 59 seconds ")); //string '2016-06-16 23:59:59' (length=19)
$sql = select * form `vvt_user` where userid = 100 AND date_time >= $dateTime2 AND date_time <= $dateTime;?>
邢天相
php日期格式轉(zhuǎn)換總結(jié):
<?php
//將當(dāng)前時(shí)間轉(zhuǎn)換成yyyy-mm-dd格式串,再轉(zhuǎn)換成日期格式,繞了一圈哈
echo strtotime(date('Y-m-d',time()).' 00:00:00');
//將GNU 日期輸入格式的字符轉(zhuǎn)換成時(shí)間
echo strtotime('now');
//標(biāo)準(zhǔn)的字符串轉(zhuǎn)換成時(shí)間
$t = '2012-9-10 15:18:06';
$time = strtotime($t);
//將時(shí)間轉(zhuǎn)換成日期字符yyyymmdd,再轉(zhuǎn)換成整型格式
$d = intval(date('Ymd',$time));
echo '付款時(shí)間:'.$d;
<?phpheader("Content-type: text/html; charset=utf-8"); $txDate = '2016-06-16';
$dateTime1 = strtotime($txDate); //int 1466028000 將英文文本日期時(shí)間解析為 Unix 時(shí)間戳:
$dateTime2= date("Y-m-d H:i:s",$dateTime1); //string '2016-06-16 00:00:00'
(length=19) Date() 函數(shù)把時(shí)間戳格式化為更易讀的日期和時(shí)間。
//拼接今日最后時(shí)間2016-06-16 23:59:59
$dateTime= date("Y-m-d H:i:s",strtotime(date("Y-m-d",strtotime($dateTime2))."+ 23 hours 59 minutes 59 seconds ")); //string '2016-06-16 23:59:59' (length=19)
$sql = select * form `vvt_user` where userid = 100 AND date_time >= $dateTime2 AND date_time <= $dateTime;?>
馬謖
還是修改 php.ini 吧date.time_zone = "Asia/Shanghai"ordate.time_zone = PRC
玉匣
$S=rand(0,23);//隨機(jī)--時(shí)$F=rand(0,59);//隨機(jī)--分$M=rand(0,59);//隨機(jī)--秒$coupon_start_time = strtotime(date('Y-m-d')." $S:$F:$M");//給這個(gè)上加上“$S,$F,$M”$coupon_end_time = strtotime(date('Y-m-d',strtotime('+30 day'))." $S:$F:$M");//給這個(gè)也上加上“$S,$F,$M”
神墓
<?php /* * author: china_skag * time: 2014-07-08 * 發(fā)博時(shí)間計(jì)算(年,月,日,時(shí),分,秒) * $createtime 可以是當(dāng)前時(shí)間 * $gettime 你要傳進(jìn)來(lái)的時(shí)間 */ 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())." 小時(shí)前"; exit(); } if($this->getMinutes() > 1) { return intval($this->getMinutes())." 分鐘前"; exit(); } if($this->getSeconds() > 1) { return intval($this->getSeconds()-1)." 秒前"; exit(); } } } //類(lèi)的使用實(shí)例 /* * * 調(diào)用類(lèi)輸出方式 * * $a = new Mygettime(time(),strtotime('-25 month')); * echo iconv('utf-8', 'gb2312', $a->index())?iconv('utf-8', 'gb2312', $a->index()):iconv('utf-8', 'gb2312', '當(dāng)前'); * */
看不懂,把源碼復(fù)制輸出的不是我要的結(jié)果。有沒(méi)有更簡(jiǎn)單的,就是取當(dāng)前時(shí)間然后給當(dāng)前時(shí)間加30分鐘的。
孫峻
php代碼如下
<?phpecho date('d', 1452126507);代碼解釋
d表示的是日(其完整格式“Y-m-d H:i:s”)
Y:代表年
m:代表月
d:代表日
H:代表時(shí)
i:代表分
s:代表秒
1452126507是時(shí)間戳
譚桂瓊
$zuihoutime應(yīng)該是任意的時(shí)間格式的字符串,如‘2013-11-27’,或者如果$zuihoutime是時(shí)間戳,直接和當(dāng)前時(shí)間比較就可以了。如果你想和讓$zuihoutime和當(dāng)前時(shí)間比較,就這樣寫(xiě):if(strtotime($zuihoutime) == time()){echo $zuihoutime;}else {echo "24小時(shí)內(nèi)沒(méi)有訪問(wèn)本站";}如果你是想判斷用戶(hù)在24小時(shí)內(nèi)有沒(méi)有訪問(wèn)本站,同時(shí)$zuihoutime是最后訪問(wèn)時(shí)間,可以這樣寫(xiě):$intervalTime = $time - strtotime($zuihoutime);if($intervalTime < 24*60*60 ){//用戶(hù)離上一次訪問(wèn)時(shí)間沒(méi)有24小時(shí)echo $zuihoutime;}else {echo "24小時(shí)內(nèi)沒(méi)有訪問(wèn)本站";}
煉剛?cè)?/span>
<?php
function udate($format = 'u', $utimestamp = null) {
if (is_null($utimestamp))
$utimestamp = microtime(true);
$timestamp = floor($utimestamp);
$milliseconds = round(($utimestamp - $timestamp) * 1000000);
return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp);
}
echo udate('Y-m-d H:i:s.u');
?>
PHP 簡(jiǎn)介
本詞條由“科普中國(guó)”百科科學(xué)詞條編寫(xiě)與應(yīng)用工作項(xiàng)目 審核 。
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本預(yù)處理器”)是一種通用開(kāi)源腳本語(yǔ)言。語(yǔ)法吸收了C語(yǔ)言、Java和Perl的特點(diǎn),利于學(xué)習(xí),使用廣泛,主要適用于Web開(kāi)發(fā)領(lǐng)域。PHP 獨(dú)特的語(yǔ)法混合了C、Java、Perl以及PHP自創(chuàng)的語(yǔ)法。它可以比CGI或者Perl更快速地執(zhí)行動(dòng)態(tài)網(wǎng)頁(yè)。用PHP做出的動(dòng)態(tài)頁(yè)面與其他的編程語(yǔ)言相比,PHP是將程序嵌入到HTML(標(biāo)準(zhǔn)通用標(biāo)記語(yǔ)言下的一個(gè)應(yīng)用)文檔中去執(zhí)行,執(zhí)行效率比完全生成HTML標(biāo)記的CGI要高許多;PHP還可以執(zhí)行編譯后代碼,編譯可以達(dá)到加密和優(yōu)化代碼運(yùn)行,使代碼運(yùn)行更快。
麗山
$str = '2009-03-30 11:10:05';$timestamp = strtotime($str);date('Y-m-d', $timestamp);簡(jiǎn)單寫(xiě)就是這樣:date('Y-m-d', strtotime('2009-03-30 11:10:05'));輸出是:2009-03-30(注意格式里的"Y-m-d"的大小寫(xiě)。)