Jump to content

[SOLVED] Simple date/time changes


penguin0

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/53928-solved-simple-datetime-changes/
Share on other sites

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.