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
Martin Paul Bannister
2,014 PointsDate & 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
Michael Nguyen
6,138 PointsEither 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
Kevin Korte
28,149 PointsI 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.
Martin Paul Bannister
2,014 PointsHi Kevin, Yes am using Apache, I will try this later Thanks for your help
Martin Paul Bannister
2,014 PointsHi Michael, Thanks for your reply, I've managed to complete this task, I read about date_default_timezone_set on www.php.net