如果時間時區不對,使用時間是要先設定時區,使用date_default_timezone_set() 設定新時區
date_default_timezone_set('asia/shanghai');
echo date("y/m/d/ h:i:s",filemtime($files));
關於date()函式
date() 函式可把時間戳格式化為可讀性更好的日期和時間。
語法: date(format,timestamp)time() 函式返回當前時間的 unix 時間戳。
time(void)$nextweek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs
echo 'now: '. date('y-m-d') ."\n";echo 'next week: '. date('y-m-d', $nextweek) ."\n";
1//方法一
2$startdate="2011-3-15 11:50:00";
3$enddate="2012-12-12 12:12:12";
4$date=floor((strtotime($enddate)-strtotime($startdate))/86400);
5$hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600);
6$minute=floor((strtotime($enddate)-strtotime($startdate))%86400/60);
7$second=floor((strtotime($enddate)-strtotime($startdate))%86400%60);
8echo
$date."天";9
echo
$hour."小時
";10
echo
$minute."分鐘
";11
echo
$second."秒
";12
//方法二
13$one = strtotime('2011-05-08 07:02:40');//
開始時間 時間戳
14$tow = strtotime('2012-12-25 00:00:00');//
結束時間 時間戳
15$cle = $tow - $one; //
得出時間戳差值
16echo
ceil($cle/60); //
得出一共多少分鐘
17echo
ceil($cle/3600); //
得出一共多少小時
18echo
ceil($cle/3600/24); //
得出一共多少天
1920
/*ceil()函式,即進一法取整
*/21
$d = cell($cle/3600/24);
22$h = cell(($cle%(3600*24))/3600); //
%取餘23
$m = cell(($cle%(3600*24))/60);
24echo "兩個時間相差 $d 天 $h 小時 $m 分"
date()函式 中format格式的各種字元表示
年 y 4 位數字完整表示的年份
y 2 位數字完整表示的年份
月m 數字表示2位
n 數字表示無前導0
f 月份字母全拼
m 3個字母縮寫
日d 日期2個數字表示
j 日期數字表示無前導0
s 日期的序數字尾
l 星期幾字母全拼表示
d 星期幾的3字母表示
w 星期幾的數字表示,週日=0週六=6
小時h 12小時兩位
g 12小時
h 24小時兩位
g 24小時
a am/pm
a am/pm0分
i 兩位數字表示
j 同上無前導0
秒s 兩位數字表示
z完整日期cr
u
echostrtotime("2020-04-07 12:34:00");
echo "現在時間是:" . date("y");//獲取4位年份
echo "現在時間是:" . intval(date("m"));//獲取月份
echo "現在時間是:" . intval(date("d"));//獲取日期,小於10的前面不加0
function getlatelytime($type = '')
//最近幾天
for($i=0;$i
<$count_day;$i++)
}elseif($type == 'week')
}elseif($type == 'month')
}elseif($type == 'year')
}return
$result;}
echo '';
print_r(getlatelytime('day'))
62 時間和日期
1.strtotime 函式 echo strtotime now 相當於將英文單詞now直接等於現在的日期和時間,並把這個日期時間轉化為unix時間戳。這個效果跟echo time 一樣。echo strtotime 1 seconds 相當於將現在的日期和時間加上了1秒,並把這個日期時間轉化為u...
golang學習系列 11 時間和日期
關於時間在實際開發運用過程中,尤其需要注意系統標準 時區帶來的影響 無論何種語言 time 包為我們提供了乙個資料型別 time.time 作為值使用 以及顯示和測量時間和日期的功能函式。type time structfunc t time day int func t time hour int...
php筆記(6) 時間與日期
time time echo time 1396193923,這個數字表示從1970年1月1日 00 00 00 到我輸出這個指令碼時經歷了1396193923秒 date函式,第二個引數取預設值的情況 echo date y m d 2014 03 30 date函式,第二個引數有值的情況 ech...