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. Link to comment https://forums.phpfreaks.com/topic/106932-mdt-to-gmt-datetime-help/ 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; ?> Link to comment https://forums.phpfreaks.com/topic/106932-mdt-to-gmt-datetime-help/#findComment-548055 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 Link to comment https://forums.phpfreaks.com/topic/106932-mdt-to-gmt-datetime-help/#findComment-548079 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)); Link to comment https://forums.phpfreaks.com/topic/106932-mdt-to-gmt-datetime-help/#findComment-548085 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... Link to comment https://forums.phpfreaks.com/topic/106932-mdt-to-gmt-datetime-help/#findComment-548129 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)); Link to comment https://forums.phpfreaks.com/topic/106932-mdt-to-gmt-datetime-help/#findComment-548134 Share on other sites More sharing options...
jonsjava Posted May 23, 2008 Share Posted May 23, 2008 Oops, sry. misunderstood the question. Link to comment https://forums.phpfreaks.com/topic/106932-mdt-to-gmt-datetime-help/#findComment-548138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.