以下是一些示例代码,展示如何在PHP中获取当前时间:
使用date函数获取当前时间:$current_time = date("Y-m-d H:i:s");echo $current_time;使用time函数获取当前时间的时间戳,并通过date函数格式化输出:$current_timestamp = time();$current_time = date("Y-m-d H:i:s", $current_timestamp);echo $current_time;使用DateTime类获取当前时间:$current_time = new DateTime();echo $current_time->format("Y-m-d H:i:s");使用Carbon库获取当前时间(需要先安装Carbon库):require 'vendor/autoload.php'; // 引入Carbon库use Carbon\Carbon;$current_time = Carbon::now();echo $current_time->toDateTimeString();这些代码中,都使用了常见的日期格式(年-月-日 时:分:秒)来格式化输出当前时间。您可以根据自己的需要,选择适合的代码来获取当前时间。

