$timeposted = "7:10pm";
This value is currently Canada time (quebec). I'm trying to find a way to convert it to France's time. How can i do that ?
php $date = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru')); echo $date->format('Y-m-d H:i:sP') . "\n"; $date->setTimezone(new DateTimeZone('Pacific/Chatham')); echo $date->format('Y-m-d H:i:sP') .
Changing Timezones of ZonedDateTime To convert a ZonedDateTime instance from one timezone to another, follow the two steps: Create ZonedDateTime in 1st timezone. You may already have it in your application. Convert the first ZonedDateTime in second timezone using withZoneSameInstant() method.
To do this, we will use the FindSystemTimeZoneById() of TimeZoneInfo class. This function takes Id as a parameter to return the equivalent time in timezone passed. In the example below, we are taking the current system time and converting it into “Central Standard Time”. DateTime currentTime = TimeZoneInfo.
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. To change the PHP timezone for an app, create a .user.ini file in the app's public directory with the following contents: date.timezone = America/Los_Angeles.
Assuming that your PHP configuration is set to the Quebec time, you can convert it to France's timezone by doing the following:
$date = new DateTime('7:10pm', new DateTimeZone('Europe/Paris'));
echo $date->format('Y-m-d H:i:sP');
Or, if your server is not set to the Quebec timezone you can:
$date = new DateTime('7:10pm', new DateTimeZone('America/Montreal'));
$date->setTimezone(new DateTimeZone('Europe/Paris'));
echo $date->format('Y-m-d H:i:sP');
which returns
2013-06-14 01:10:00+02:00
You can read more about PHP and timezones here: http://www.php.net/manual/en/datetime.settimezone.php
Use the date_default_timezone_set() function of PHP.
If you want to change it to France you would use the
date_default_timezone_set('Europe/Paris');
a list of Supported Timezones can be found here: http://www.php.net/manual/en/timezones.php
The functionality of date_default_timezone_set() can be found here: http://php.net/manual/en/function.date-default-timezone-set.php
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