We can use the function date() which accepts the date format and timestamp as arguments.
Syntax
date(format,timestamp)
Here are some common characters for dates:
Common characters for time:
echo date("d/m/Y g:ia"); // 16/11/2022 9:22am
You can check more PHP datetime format here.
We can echo out the current timezone with the function date_default_timezone_get()
echo date_default_timezone_get(); // Europe/Berlin
We can config the timezone using the function date_default_timezone_set()
and pass in the valid timezone.
Here is the list of supported timezones.
date_default_timezone_set("Asia/Tokyo");
date_default_timezone_set("UTC");
We can convert textual datetime into unit timestamp using strtotime()
function.
echo date("d/m/Y g:ia", strtotime("next Monday")); // 21/11/2022 12:00am
You can check the relative format here.