Link to home
Start Free TrialLog in
Avatar of yarekGmail
yarekGmail

asked on

php : time transformations

Hello experts
I have a server hosted in US.

When I use: date("Y-m-d H:i");
It returns the local server time which is GMT-5

My question is : how can I get the time from Paris (+1 hour) ?
Regards
ASKER CERTIFIED SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mahdi78
Use this code


<?
$timezone  = +1; //(GMT +1:00)
echo gmdate("Y/m/j H:i:s", time() + 3600*($timezone+date("I")));
?>

Open in new window

Have a look here: http://www.php.net/manual/en/function.date.php

specifically at the Timezone section:

Timezone       ---       ---
e       Timezone identifier (added in PHP 5.1.0)       Examples: UTC, GMT, Atlantic/Azores
I (capital i)       Whether or not the date is in daylight saving time       1 if Daylight Saving Time, 0 otherwise.
O       Difference to Greenwich time (GMT) in hours       Example: +0200
P       Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)       Example: +02:00
T       Timezone abbreviation       Examples: EST, MDT ...
Z       Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.       -43200 through 50400

You can also have a look here: http://www.php.net/manual/en/function.date-default-timezone-set.php
Rik-Legger is correct.  This article explains how it all works.  See the first code snippet.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html