RazorMaster Posted May 23, 2008 Share Posted May 23, 2008 Hi, I need to convert MDT time to GMT time. I have this php code to output a date/time format: $example[$count]['startdate'] = date("j/n/Y", $info['example_start']); The output for this is: 23/05/2008 07:00 MDT But I need this is GMT (0): 23/05/2008 14:00 GMT The ['example_start'] is a unix date/time. I just can't understand how to use mktime() or gmmktime() in here to output correct timezone date/hour... Any help? Thanks. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 23, 2008 Share Posted May 23, 2008 <?php $hour = date("G") + 7; $minute = date("i"); if ($hour >= 24){ $hour = $hour - 24; //converts it to the next day $day_increment = 1; //add a day } else { $day_increment = 0; } $day = date("j") + $day_increment; $month = date("n"); $year = date("Y"); $numberOfDays = date("d", mktime(0, 0, 0, $month + 1, 0, $year)); if ($day > $numberOfDays){ $day = 1; $month = $month + 1; if ($month > 12){ $month = 1; $year = $year + 1; } } $date = $day."/".$month."/".$year." ".$hour.$minute; print $date; ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 23, 2008 Share Posted May 23, 2008 If this solved your problem, could you please click on the "solved" button, and if it didn't, could you please let us know? Thanks Quote Link to comment Share on other sites More sharing options...
moon 111 Posted May 23, 2008 Share Posted May 23, 2008 Try: $example[$count]['startdate'] = date("j/n/Y", $info['example_start'] + (60 * 60 * 7)); Quote Link to comment Share on other sites More sharing options...
RazorMaster Posted May 23, 2008 Author Share Posted May 23, 2008 Well, the first option just give me the actual date/time and is not converting the unix date/time posted... The second option works just fine... But, how to convert this??? $example[$count]['example_timezone'] = date("T", $info['example_time']); This is returning "MDT" instead "GMT". Any chance to convert this??? PS: Thanks a lot to jonsjava... Its a great code to display actual date/time in GMT timezone... Quote Link to comment Share on other sites More sharing options...
Haggis Posted May 23, 2008 Share Posted May 23, 2008 $example[$count]['example_timezone'] = date("T", $info['example_time'] + (60 * 60 * 7)); Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 23, 2008 Share Posted May 23, 2008 Oops, sry. misunderstood the question. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.