PHP日期與時間,PHP日期時間_PHP教程

來源:互聯網
上載者:User

PHP日期與時間,PHP日期時間


1、date

string date ( string $format [, int $timestamp ] )

                echo date('Y') . '
';// 2016
echo date('y') . '
';// 16

echo '------
';

echo date('m') . '
';// 03
echo date('M') . '
';// Mar, 大寫M表示月份的3個縮寫字元
echo date('n') . '
';// 3,
echo date('F') . '
';// March, 月份的英文全寫

echo '------
';

echo date('d') . '
';// 09
echo date('j') . '
';// 9
echo date('S') . '
';// th,表示日期的尾碼。

echo '------
';

echo date('g') . '
';// 4, 12小時制,前不帶0
echo date('G') . '
';// 16, 24小時制,帶前置0
echo date('H') . '
';// 16,24小時制,前不帶0
echo date('h') . '
';// 01, 12小時制,帶前置0

echo '------
';

echo date('i') . '
';// 42,分鐘

echo '------
';

echo date('s') . '
';// 26,秒
echo date('S') . '
';// th,表示日期的尾碼。

echo '------
';

echo date('a') . '
';// pm,小寫am(上午)pm(下午)
echo date('A') . '
';// PM,大寫

echo '------
';

echo date('l') . '
';// Thursday,當天是星期幾的英文全寫(Tuesday)
echo date('L') . '
';// 1,閏年則返回1否則0
echo date('D') . '
';// Thu,表示星期幾的3個字元縮寫(Tue)


2、mktime()

mktime為指定時間產生時間戳記,原型:

int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [,int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1]]]]]]] )

$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "明天是 ".date("Y/m/d", $tomorrow);

3、strtotime()

$d=strtotime("10:38pm April 15 2015");
echo "建立日期是 " . date("Y-m-d h:i:sa", $d);

$d=strtotime("tomorrow");
echo date("Y-m-d h:i:sa", $d) . "
";

$d=strtotime("next Saturday");
echo date("Y-m-d h:i:sa", $d) . "
";

$d=strtotime("+3 Months");
echo date("Y-m-d h:i:sa", $d) . "
";

http://www.bkjia.com/PHPjc/1113140.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1113140.htmlTechArticlePHP日期與時間,PHP日期時間 1、date string date ( string $format [, int $timestamp ] ) echo date('Y') . 'br/';// 2016 echo date('y') . 'br/';// 16 echo '------br/'; echo...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.