penguin0 Posted June 2, 2007 Share Posted June 2, 2007 I am trying to modify this so it will say eastern time. <? echo date("m/d/Y - h:i:s A"); ?> Can someone show me how to add time to the H & I. I know you can use microtime () or strtotime() but I am not sure how to do this. Also is there a way to make it display that by what time the user suggests? Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/ Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 to make this easier, I need to just add 55 minutes, I believe... Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-266640 Share on other sites More sharing options...
obsidian Posted June 2, 2007 Share Posted June 2, 2007 I am trying to modify this so it will say eastern time. <? echo date("m/d/Y - h:i:s A"); ?> Here's a start: <?php // using strtotime() echo date('m/d/Y - h:i:s A', strtotime("now + 55 minutes")); // using time() echo date('m/d/Y - h:i:s A', time() + (55 * 60)); ?> Good luck Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-266641 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 thanks, worked great. Now I want to make a script to format that by what time zone the user is in. Can anyone give me a good example using 2 different timezones? Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-266652 Share on other sites More sharing options...
obsidian Posted June 2, 2007 Share Posted June 2, 2007 thanks, worked great. Now I want to make a script to format that by what time zone the user is in. Can anyone give me a good example using 2 different timezones? Well, if you do something like most forums do, you can have the user declare their timezone with +/- the number of hours (for instance, for me, it's EST or -5). Here's a Wikipedia page that has more detail about time zones than anyone needs to know ... anyway, once you know their timezone offset, you can just do something like this: <?php $hour = 60 * 60; // # of seconds in one hour $user_tz = -5; // EST // using strtotime() $def = "now $user_tz hours"; echo date('m/d/Y - h:i:s A', strtotime($def)); // using time() echo date('m/d/Y - h:i:s A', time() + ($hour * $user_tz)); ?> Good luck with that. Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-266843 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 OK, I think I got this to work: to change the time: <tr><td>Time Zone</td><td><select name="timezone"> <option value="-12" ' . ($userstime == -12 ? 'selected="selected"' : '') . '>GMT - 12 Hours</option> <option value="-11" ' . ($userstime == -11 ? 'selected="selected"' : '') . '>GMT - 11 Hours</option> <option value="-10" ' . ($userstime == -10 ? 'selected="selected"' : '') . '>GMT - 10 Hours</option> <option value="-9" ' . ($userstime == -9 ? 'selected="selected"' : '') . '>GMT - 9 Hours</option> <option value="-8" ' . ($userstime == -8 ? 'selected="selected"' : '') . '>GMT - 8 Hours</option> <option value="-7" ' . ($userstime == -7 ? 'selected="selected"' : '') . '>GMT - 7 Hours</option> <option value="-6" ' . ($userstime == -6 ? 'selected="selected"' : '') . '>GMT - 6 Hours</option> <option value="-5" ' . ($userstime == -5 ? 'selected="selected"' : '') . '>GMT - 5 Hours</option> <option value="-4" ' . ($userstime == -4 ? 'selected="selected"' : '') . '>GMT - 4 Hours</option> <option value="-3.5" ' . ($userstime == -3.5 ? 'selected="selected"' : '') . '>GMT - 3.5 Hours</option> <option value="-3" ' . ($userstime == -3 ? 'selected="selected"' : '') . '>GMT - 3 Hours</option> <option value="-2" ' . ($userstime == -2 ? 'selected="selected"' : '') . '>GMT - 2 Hours</option> <option value="-1" ' . ($userstime == -1 ? 'selected="selected"' : '') . '>GMT - 1 Hour</option> <option value="0" ' . ($userstime == 0 ? 'selected="selected"' : '') . '>GMT</option> <option value="1" ' . ($userstime == 1 ? 'selected="selected"' : '') . '>GMT + 1 Hour</option> <option value="2" ' . ($userstime == 2 ? 'selected="selected"' : '') . '>GMT + 2 Hours</option> <option value="3" ' . ($userstime == 3 ? 'selected="selected"' : '') . '>GMT + 3 Hours</option> <option value="3.5" ' . ($userstime == 3.5 ? 'selected="selected"' : '') . '>GMT + 3.5 Hours</option> <option value="4" ' . ($userstime == 4 ? 'selected="selected"' : '') . '>GMT + 4 Hours</option> <option value="4.5" ' . ($userstime == 4.5 ? 'selected="selected"' : '') . '>GMT + 4.5 Hours</option> <option value="5" ' . ($userstime == 5 ? 'selected="selected"' : '') . '>GMT + 5 Hours</option> <option value="5.5" ' . ($userstime == 5.5 ? 'selected="selected"' : '') . '>GMT + 5.5 Hours</option> <option value="6" ' . ($userstime == 6 ? 'selected="selected"' : '') . '>GMT + 6 Hours</option> <option value="6.5" ' . ($userstime == 6.5 ? 'selected="selected"' : '') . '>GMT + 6.5 Hours</option> <option value="7" ' . ($userstime == 7 ? 'selected="selected"' : '') . '>GMT + 7 Hours</option> <option value="8" ' . ($userstime == 8 ? 'selected="selected"' : '') . '>GMT + 8 Hours</option> <option value="9" ' . ($userstime == 9 ? 'selected="selected"' : '') . '>GMT + 9 Hours</option> <option value="9.5" ' . ($userstime == 9.5 ? 'selected="selected"' : '') . '>GMT + 9.5 Hours</option> <option value="10" ' . ($userstime == 10 ? 'selected="selected"' : '') . '>GMT + 10 Hours</option> <option value="11" ' . ($userstime == 11 ? 'selected="selected"' : '') . '>GMT + 11 Hours</option> <option value="12" ' . ($userstime == 12 ? 'selected="selected"' : '') . '>GMT + 12 Hours</option> <option value="13" ' . ($userstime == 13 ? 'selected="selected"' : '') . '>GMT + 13 Hours</option> </select></td></tr>'; to display the time: <? $userstime = $a_row['timezone']; ?><? $offtime = "now + $userstime hours"; ?><? echo date('m/d/Y - h:i:s A', strtotime($offtime)); ?> the problem is I have it set to -5 for my time, but the time is not starting at GMT, it is starting at the server time, is there a way to just start at gmt, or how can I offset this: @ 1:29pm Eastern it says 5:34 (when the offset is set to -5). Before the script I used this to get to eastern: <? echo date('m/d/Y - h:i:s A', strtotime("now + 175 minutes")); ?> Also It will not show AM or PM when using the offset. Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267041 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 scratch the part about not showing am or pm.. Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267064 Share on other sites More sharing options...
chigley Posted June 2, 2007 Share Posted June 2, 2007 ini_set("date.timezone", "Europe/London"); Will reset the timezone to GMT before you offset it. Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267068 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 i put that in the code but nothing changed. Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267072 Share on other sites More sharing options...
chigley Posted June 2, 2007 Share Posted June 2, 2007 Did you put it at the very top? Put this at the very top of your code: error_reporting(E_ALL); ini_set('error_reporting', E_ALL); ini_set("date.timezone", "Europe/London"); Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267074 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 only tells me errors about non date things. Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267075 Share on other sites More sharing options...
chigley Posted June 2, 2007 Share Posted June 2, 2007 What version of PHP are you running? I think that the date.timezone is only for version 5+ Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267079 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 yeah I am running PHP Version 4.4.4 Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267082 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 <? echo date('m/d/Y - h:i:s A', strtotime("now + 475 minutes")); ?> this will get it to gmt, but how can I then use date() again? Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267083 Share on other sites More sharing options...
chigley Posted June 2, 2007 Share Posted June 2, 2007 putenv("TZ=Europe/London"); Try that? Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267085 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 it is still at the same time as with ini_set("date.timezone", "Europe/London"); IE the servertime + offset Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267095 Share on other sites More sharing options...
penguin0 Posted June 2, 2007 Author Share Posted June 2, 2007 FIXED: $datetime = date('m/d/Y - h:i:s A', strtotime("now + 475 minutes + $userstime hours")); Quote Link to comment https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/#findComment-267103 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.