PHP一行代碼擷取時間戳記

來源:互聯網
上載者:User

標籤:sunday   mktime   星期幾   時間   mon   今天   strtotime   相關   ==   


擷取當天零點時間戳記
$today = date(‘Y-m-d’,time());
$todaytime = strtotime($today);

本周一
echo date(‘Y-m-d‘,(time()-((date(‘w‘)==0?7:date(‘w‘))-1)*24*3600)); //w為星期幾的數字形式,這裡0為周日

本周日
echo date(‘Y-m-d‘,(time()+(7-(date(‘w‘)==0?7:date(‘w‘)))*24*3600)); //同樣使用w,以現在與周日相關天數算

上周一
echo date(‘Y-m-d‘,strtotime(‘-1 monday‘, time())); //無論今天幾號,-1 monday為上一個有效周未

上周日
echo date(‘Y-m-d‘,strtotime(‘-1 sunday‘, time())); //上一個有效周日,同樣適用於其它星期

本月一日
echo date(‘Y-m-d‘,strtotime(date(‘Y-m‘, time()).‘-01 00:00:00‘)); //直接以strtotime產生

本月最後一日
echo date(‘Y-m-d‘,strtotime(date(‘Y-m‘, time()).‘-‘.date(‘t‘, time()).‘ 00:00:00‘)); //t為當月天數,28至31天

上月一日
echo date(‘Y-m-d‘,strtotime(‘-1 month‘, strtotime(date(‘Y-m‘, time()).‘-01 00:00:00‘))); //本月一日直接strtotime上減一個月

上月最後一日
echo date(‘Y-m-d‘,strtotime(date(‘Y-m‘, time()).‘-01 00:00:00‘)-86400); //本月一日減一天即是上月最後一日

$monday = time() - ((date(‘w‘) == 0 ? 7 : date(‘w‘)) - 1) * 24 * 3600; 周一
$monday = mktime(0, 0, 0, date(‘m‘,$monday), date(‘d‘,$monday), date(‘y‘,$monday)); 周一0點

PHP一行代碼擷取時間戳記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.