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 trialKonrad Pilch
2,435 PointsHow are these two connected?
HI,
Im making this here starting as with variable etc.. but i see im wrong and i see that the code should be like :
date_default_timezone_set('UK, Leicester');
$time = date('h:i:s a',time());
How is this connected to each other?
There isnt like any logic in it . Unless the date defualt is set as time and im passing it to the date as time or i dont know .
1 Answer
Jose Soto
23,407 PointsThe connection is via the server you are using. The php.ini file on the server usually has a default timezone. So when the date or time command is called, it will use the server's date or time.
Within a specific php script, you can change the timezone by callling 'date_default_timezone_set' and pass it any of the supported timezone strings.
The following two scripts were run on the same server:
<?php
date_default_timezone_set('Europe/London');
$time = date('h:i:s a',time());
echo $time; // Output = 12:16:39 am
<?php
date_default_timezone_set('America/Los_Angeles');
$time = date('h:i:s a',time());
echo $time; // Output = 04:16:14 pm
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsAa i get it now ;) thank you!