The code for the date and time function:
function date_and_time($format,$timestamp) {
$date_and_time = date($format,$timestamp);
return $date_and_time;
}
And then the code to display it:
<?php
echo date_and_time("dS F Y", strtotime($profile[last_activity_date_and_time]));
?>
The value of $profile[last_activity_date_and_time] is 2010-01-18 14:34:04
When displayed it shows up as 18th January 2010 - 02:34pm
But, is there any way to change the timezone it is displayed in?
We can also use the function date_default_timezone_set to set the default timezone and use a different timezone to convert the date and time from the default timezone to the given timezone as shown below. This is the easiest way to convert the time from one clock to another using the DateTime and DateTimeZone classes.
Open Hosting → Manage → PHP Configuration page. There, open the PHP options tab and edit the date. timezone value: If you are not sure which time zone to insert, check the Time Zone Map.
The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts. See PHP's list of supported timezones to find the names of all possible timezones you can use for the date.
ini file is located at the /etc directory. Depending on the installed version of PHP version, you will find a [Date] section like the following. If it is not there, just add a line with the "date. timezone = Your/Timezone" function.
Not sure if this what you're looking for, but try DateTime
date_default_timezone_set('Europe/London');
$datetime = new DateTime();
$datetime->setTimestamp($yourTimestamp);
echo $datetime->getTimezone()->getName();
echo $datetime->format(DATE_ATOM);
$la_time = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($la_time);
echo $datetime->getTimezone()->getName();
echo $datetime->format(DATE_ATOM);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With