太史亨
php日期格式轉(zhuǎn)換總結(jié):
<?php
//將當(dāng)前時間轉(zhuǎn)換成yyyy-mm-dd格式串,再轉(zhuǎn)換成日期格式,繞了一圈哈
echo strtotime(date('Y-m-d',time()).' 00:00:00');
//將GNU 日期輸入格式的字符轉(zhuǎn)換成時間
echo strtotime('now');
//標(biāo)準(zhǔn)的字符串轉(zhuǎn)換成時間
$t = '2012-9-10 15:18:06';
$time = strtotime($t);
//將時間轉(zhuǎn)換成日期字符yyyymmdd,再轉(zhuǎn)換成整型格式
$d = intval(date('Ymd',$time));
echo '付款時間:'.$d;
<?phpheader("Content-type: text/html; charset=utf-8"); $txDate = '2016-06-16';
$dateTime1 = strtotime($txDate); //int 1466028000 將英文文本日期時間解析為 Unix 時間戳:
$dateTime2= date("Y-m-d H:i:s",$dateTime1); //string '2016-06-16 00:00:00'
(length=19) Date() 函數(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)前時間轉(zhuǎn)換成yyyy-mm-dd格式串,再轉(zhuǎn)換成日期格式,繞了一圈哈
echo strtotime(date('Y-m-d',time()).' 00:00:00');
//將GNU 日期輸入格式的字符轉(zhuǎn)換成時間
echo strtotime('now');
//標(biāo)準(zhǔn)的字符串轉(zhuǎn)換成時間
$t = '2012-9-10 15:18:06';
$time = strtotime($t);
//將時間轉(zhuǎn)換成日期字符yyyymmdd,再轉(zhuǎn)換成整型格式
$d = intval(date('Ymd',$time));
echo '付款時間:'.$d;
<?phpheader("Content-type: text/html; charset=utf-8"); $txDate = '2016-06-16';
$dateTime1 = strtotime($txDate); //int 1466028000 將英文文本日期時間解析為 Unix 時間戳:
$dateTime2= date("Y-m-d H:i:s",$dateTime1); //string '2016-06-16 00:00:00'
(length=19) Date() 函數(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ī)--時$F=rand(0,59);//隨機(jī)--分$M=rand(0,59);//隨機(jī)--秒$coupon_start_time = strtotime(date('Y-m-d')." $S:$F:$M");//給這個上加上“$S,$F,$M”$coupon_end_time = strtotime(date('Y-m-d',strtotime('+30 day'))." $S:$F:$M");//給這個也上加上“$S,$F,$M”
神墓
<?php /* * author: china_skag * time: 2014-07-08 * 發(fā)博時間計算(年,月,日,時,分,秒) * $createtime 可以是當(dāng)前時間 * $gettime 你要傳進(jìn)來的時間 */ 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(); } } } //類的使用實例 /* * * 調(diào)用類輸出方式 * * $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é)果。有沒有更簡單的,就是取當(dāng)前時間然后給當(dāng)前時間加30分鐘的。
孫峻
php代碼如下
<?phpecho date('d', 1452126507);代碼解釋
d表示的是日(其完整格式“Y-m-d H:i:s”)
Y:代表年
m:代表月
d:代表日
H:代表時
i:代表分
s:代表秒
1452126507是時間戳
譚桂瓊
$zuihoutime應(yīng)該是任意的時間格式的字符串,如‘2013-11-27’,或者如果$zuihoutime是時間戳,直接和當(dāng)前時間比較就可以了。如果你想和讓$zuihoutime和當(dāng)前時間比較,就這樣寫:if(strtotime($zuihoutime) == time()){echo $zuihoutime;}else {echo "24小時內(nèi)沒有訪問本站";}如果你是想判斷用戶在24小時內(nèi)有沒有訪問本站,同時$zuihoutime是最后訪問時間,可以這樣寫:$intervalTime = $time - strtotime($zuihoutime);if($intervalTime < 24*60*60 ){//用戶離上一次訪問時間沒有24小時echo $zuihoutime;}else {echo "24小時內(nèi)沒有訪問本站";}
煉剛?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 簡介
本詞條由“科普中國”百科科學(xué)詞條編寫與應(yīng)用工作項目 審核 。
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本預(yù)處理器”)是一種通用開源腳本語言。語法吸收了C語言、Java和Perl的特點,利于學(xué)習(xí),使用廣泛,主要適用于Web開發(fā)領(lǐng)域。PHP 獨特的語法混合了C、Java、Perl以及PHP自創(chuàng)的語法。它可以比CGI或者Perl更快速地執(zhí)行動態(tài)網(wǎng)頁。用PHP做出的動態(tài)頁面與其他的編程語言相比,PHP是將程序嵌入到HTML(標(biāo)準(zhǔn)通用標(biāo)記語言下的一個應(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);簡單寫就是這樣:date('Y-m-d', strtotime('2009-03-30 11:10:05'));輸出是:2009-03-30(注意格式里的"Y-m-d"的大小寫。)