PHP獲取時間

2022-08-15 17:12:16 字數 1053 閱讀 7824

<?php

header("content-type:text/html;charset=utf-8");

//prc代指中國時間,新增後可以正確獲取中國時間

date_default_timezone_set('prc');

//獲取當前電腦的時間

echo '現在的時間是:'.date('y-m-d h:i:s');

echo '

';echo '

';//獲取昨天的現在時間(方法1)

echo '昨天的現在的時間是:'.date('y-m-d h:i:s', strtotime('-1 day'));

echo '

';//獲取昨天的現在時間(方法2)

echo '昨天的現在的時間是:'.date('y-m-d h:i:s', time()-86400);

echo '

';//獲取上周二的現在時間

echo '上周二的現在的時間是:'.date('y-m-d', strtotime('last tuesday -1 week')).date(' h:i:s');

echo '

';//獲取明天的現在時間(方法1)

echo '明天的現在的時間是:'.date('y-m-d h:i:s', strtotime('+1 day'));

echo '

';//獲取明天的現在時間(方法2)

echo '明天的現在的時間是:'.date('y-m-d h:i:s', time()+86400);

echo '

';//獲取下周一的現在時間

echo '下周一的現在的時間是:'.date('y-m-d', strtotime('next monday')).date(' h:i:s');

echo '

';//顯示本月的第一天的日期

echo '本月第一天是:'.date('y-m-01');

echo '

';//顯示本月的最後一天的日期

echo '本月最後一天是:'.date('y-m-t');

echo '

';

php獲取時間

1 獲取當前日期的前一天 thedate date ymd mktime 0,0,0,date m date d 1,date y 2 獲取指定時間的前一天和後一天 yesterday date y m d strtotime thedate.1 day 前一天 tomorrow date y m ...

php 獲取時間

year date y 年 2018 如果 y 小寫,輸出是年份簡寫,如 2018年,輸出是 18 month date m 月 2 如果 m 大寫,輸出是英文月份,小寫是數字 day date d 日 week date l 星期幾 last month days cal days in mont...

php 獲取時間

獲取指定時間的本月起止時間 param time int return mixed 11 function currentmonth time 獲取指定時間的上個月起止時間 param time int return mixed 11 function lastmonth time 獲取指定時間下個...