Solved

php : time transformations

Posted on 2011-09-25
5
235 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
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 108

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php mail headers 2 12
echo button 13 47
.htaccess file settings 4 35
PHP json decode 9 0
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now