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?"
Related snippets:
- Add minutes to date time in PHP
- Add days to date in PHP
- Get same day in the next week in PHP
- Get time difference in minutes in PHP
- Convert date to timestamp in PHP
- Convert timestamp to DateTime in PHP
- Get the last day of a month from date in PHP
- Get the number of days between two dates in PHP
- Get yesterday's date in PHP
- Get tomorrow's date in PHP
- Get current time in PHP
- Get actual date in PHP
Tags:
current time, actual time, current time in different time zone, time, timezone Technical term:
Get current time in PHP