Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Date & Time stamp

Hi,

Am studying PHP at college, and I need to add a date and time stamp to an order page. I've managed to do this, but when I run my code, the time is plus 1 hour. How do I set time to GMT

My code looks like this:

$today = date("l j F, Y, g:i a"); echo " Thanks for your order placed on $today \n";

4 Answers

Either set time zone in PHP.INI or in your code

In php.ini

date.timezone = "America/Los_Angeles"

in your code

date_default_timezone_set('America/Los_Angeles');

replace 'America/Los_Angeles' with timezone you want

I believe you have to set your timezone in your server's ini files. Are you using apache? I did this a while back when I used PHP's date function, and at first my times were wrong. I found an answer on StackOverflow on how to adjust time timezone in a ini file in my apache server, and it's worked correctly ever sense.

Now, keep in mind that for users in other time zones, that time will be wrong to them. Where as I believe Javascript uses the computers local time, not the servers.

Hi Kevin, Yes am using Apache, I will try this later Thanks for your help

Hi Michael, Thanks for your reply, I've managed to complete this task, I read about date_default_timezone_set on www.php.net