php中的日期

來源:互聯網
上載者:User

標籤:

1、在PHP中擷取日期和時間

 time()返回目前時間的 Unix 時間戳記。 getDate()返回日期/時間資訊。 gettimeofday()返回目前時間資訊。date_sunrise()返回給定的日期與地點的日出時間。date_sunset();返回給定的日期與地點的日落時間。

2、將時間戳記的格式轉了 我們可以讀懂的時間格式

date(string, [timestamp]);

3、將日期和時間轉變成UNIX時間戳記

mktime() 函數返回一個日期的 Unix 時間戳記。

文法:mktime(hour,minute,second,month,day,year,is_dst);
例子:
<?phpecho(date("M-d-Y",mktime(0,0,0,12,36,2001)));echo(date("M-d-Y",mktime(0,0,0,14,1,2001)));echo(date("M-d-Y",mktime(0,0,0,1,1,2001)));echo(date("M-d-Y",mktime(0,0,0,1,1,99)));?>

輸出:

Jan-05-2002Feb-01-2002Jan-01-2001Jan-01-1999

4、修改PHP的預設時區

* php.ini
* date.timezone=
*
*Asia/Shanghai
*PRC
*Gtc/GET-8

 

5、使用微妙計算PHP指令碼執行的時間。

 microtime();

 

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.