php 擷取時間的方法

來源:互聯網
上載者:User
本篇介紹了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_month(CAL_GREGORIAN, $month-1,$year);// 上一月的天數 $month = date("m")$now_month_days = cal_days_in_month(CAL_GREGORIAN, $month,$year);// 當年月的天數; $month = date("m")cal_days_in_month 的公用:返回某個曆法中某年中某月的天數$next_month_days=cal_days_in_month(CAL_GREGORIAN,$month+1,$year);if($year%4==0 && $now_month_days==28){$now_month_days = $now_month_days+1;// 判斷當前月是不閏年,是的話 2月加一天,即29天}$week_date = date("w",strtotime("2018-2-5")); // 字串指定日期獲得星期幾$week_date = date("w",strtotime(date("Y-m-d))); // 變數指定日期獲得星期幾$week_date = date("w",strtotime($year."-".$month."-"."1"));//拼接字串指定每月 1 號期,獲得星期幾   cal_days_in_month 的公用:返回某個曆法中某年中某月的天數

參數介紹:

cal_days_in_month(par1,par2,$par3);

$par1 :用來計算的某種曆法,PHP Calendar 常量

par2:參數par1選中曆法中的某個月

$par3: 選中曆法中的某一年

傳回值:

$par1 選中曆法的某年某月的天數

PHP Calendar 常量:日曆擴充包含了簡化不同日曆格式間轉換的函數。

為了讓這些函數能夠工作,您必須通過 –enable-calendar 編譯 PHP。window下,已經整合了對日曆擴充的支援

案例中的常量CAL_GREGORIAN,是PHP預定義的常量,就像PHP_OS等常量

gregorian 的意思:西曆;陽曆

本篇介紹了php擷取時間的方法,更多相關內容請關注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.