Solved

php : time transformations

Posted on 2011-09-25
5
250 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:yarekGmail
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 36595358
Put this in front of your code:

date_default_timezone_set('Europe/Paris');

Open in new window


http://php.net/manual/en/function.date-default-timezone-set.php
http://www.php.net/manual/en/timezones.europe.php
0
 
LVL 9

Expert Comment

by:Mahdi78
ID: 36595361
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

0
 
LVL 17

Expert Comment

by:psimation
ID: 36595377
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
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36595444
Rik-Legger is correct.  This article explains how it all works.  See the first code snippet.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question