php函數date的使用方法

date 函數是 PHP 中的內置函數,用于格式化當前日期和時間。

語法:

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

參數:

  • format:指定格式化字符串,可以使用特殊字符表示日期和時間的元素。
  • timestamp:可選參數,指定要格式化的時間戳。

例如:

$today = date("Y-m-d H:i:s");
echo "Today is $today";

運行以上代碼後,將得到以下輸出:

Today is 2023-02-10 09:48:50

可以看到,函數將當前日期和時間格式化為 Y-m-d H:i:s 的形式。

請注意,可以使用的格式化字符串的詳細信息可以在 PHP 文檔中查找:https://www.php.net/manual/en/function.date.php

發布者:彬彬筆記,轉載請註明出處:https://www.binbinbiji.com/zh-hant/php/3032.html

(0)
彬彬筆記彬彬筆記
上一篇 2023年2月11日
下一篇 2023年2月12日

相關推薦

發表回復

登錄後才能評論
蜀ICP備14017386號-13