cwz7 Posted January 30, 2009 Share Posted January 30, 2009 Hi I am coding a website using PHP and would like to display the server time, but according to the timezone of the user. I would also like to keep a copy of the timestamp in the database. Can someone advise? Thank you! Link to comment https://forums.phpfreaks.com/topic/143120-setting-timezone-with-php-gmmktime/ Share on other sites More sharing options...
printf Posted January 30, 2009 Share Posted January 30, 2009 Quick example... <? // usage // how many hours is the users time +13 <-- 0 --> -12 away from GMT // ( 15 minutes as ( .25), half hours as ( .5 ), 45 minutes as ( .75 ) ) $user_offset = '-5'; // user is in New York Time // output format (time display) $format = 'l dS of F Y h:i:s A'; // time now (GMT) or a timestamp from your database $time = time(); // run it echo offset_time ( $time, $format, $user_offset ); function offset_time ( $time_stamp, $time_format, $time_offset ) { return gmdate ( $time_format, $time_stamp + ( 3600 * $time_offset ) ); } ?> Link to comment https://forums.phpfreaks.com/topic/143120-setting-timezone-with-php-gmmktime/#findComment-750590 Share on other sites More sharing options...
cwz7 Posted January 30, 2009 Author Share Posted January 30, 2009 Thank you very much for your reply! Easy to understand and apply.. Link to comment https://forums.phpfreaks.com/topic/143120-setting-timezone-with-php-gmmktime/#findComment-750596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.