- Instant help with your Php coding problems

Get current time in PHP

Question:
How to get current time in PHP?
Answer:
// Current time in server timezone
$currentTime = date('H:i:s');

// Current time in selected timezone
date_default_timezone_set('America/New_York');
$currentTimeNY = date('H:i:s');
Description:

To get the current time, simply use the date function with the appropriate format string. To get only hours and minutes use H:i and if you also need the seconds, then use the H:i:s format string.

It is important that the date function is based on the time zone set on the server. If you want to query the current time in another time zone, you must first set the desired time zone with the date_default_timezone_set function.

Reference:
Supported timezones
Share "How to get current time in PHP?"
Interesting things
ChatGPT in a nutshell