Aug 23, 2010

Handling date with PHP (Second Part)

Getting Time And Date With PHP
My computer's local time is 9:34:08, so That is also the output. Now we'll try to change the timezone: Now we'll try to change the time zone:
date_default_timezone_set ('America / New_York');
echo date('H:i:s'); echo date ('H: i: s');  
What if You Have users from multiple time zones? Still simple! Still simple! Ask them what their timezone is and set it accordingly. Ask Them what their time zone and set it accordingly. The function timezone_identifiers_list() gives you an array of all the timezone identifiers, so you can use that to generate a drop down list they can choose from. The function timezone_identifiers_list () gives you an array of all the timezone identifiers, so That You Can Use to Generate a drop down list Can They choose from. You can also try out geolocating, but that is beyond the scope of this tutorial. You Can Also try out geolocating, but That is beyond the scope of this tutorial.

Finally, PHP has a function called gmdate() , which always formats the date in GMT. Finally, Has a PHP function Called gmdate () , Which always formats the date in GMT. If you know the offset in seconds you can do like: If you know the offset in seconds you can do like:
 gmdate ('H: i: s', time () + $ offset); 
So You Might Do
 gmdate ('H: i: s', time () + 3600); 
for an offset of one hour. However, this requires you to take DST into consideration. However, this Requires you to take DST Writing considération. Not all countries observe DST, and some do it differently than others. Not all countries Observe DST, and Some Do It Differently Than others. My recommendation would be to use PHP's built-in support for timezones. My Recommendation Would be to use PHP's built-in support for time zones.

No comments: