jakebur01 Posted August 12, 2008 Share Posted August 12, 2008 I am having trouble putting the puzzle together. I have a form with timezone, hour, day, and year. Ex. of time zone option: <option value="-7">GMT - 7 Hours (MOUNTAIN STANDARD TIME-USA-CANADA)</option> <option value="-6">GMT - 6 Hours (CENTRAL STANDARD TIME-USA-CANADA)</option> <option value="-5">GMT - 5 Hours (EASTERN STANDARD TIME-USA-CANADA)</option> <option value="-4">GMT - 4 Hours (ATLANTIC STANDARD TIME)</option> <option value="-3">GMT - 3 Hours</option> <option value="-2">GMT - 2 Hours (AZORES TIME)</option> <option value="-1">GMT - 1 Hours (WEST AFRICA TIME)</option> <option value="+0">GMT (WESTERN EUROPEAN TIME)</option> I am posting this to a page where I need to convert the time and date into a timestamp according to the timezone they chose. Note: The server is sitting on central time zone. $hour=$_POST['hour']; $month=$_POST['month']; $day=$_POST['day']; $year=$_POST['year']; $timezone=$_POST['timezone']; $currenttimezone="-6"; $finalhour= $timestamp = mktime($finalhour, 0, 0, $month, $day, $year); I stopped..... I really don't know what I am doing here. My current timezone is -6(central time). I am using this for a scheduled chat time. So if someone scheduled it for 2 pm china time, they would be able to access the chat at that time. Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/ Share on other sites More sharing options...
revraz Posted August 12, 2008 Share Posted August 12, 2008 $finalhour=$hour - $currenttimezone; But $currenttimezone needs to be a INT not a string. Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614729 Share on other sites More sharing options...
jakebur01 Posted August 12, 2008 Author Share Posted August 12, 2008 I'm confused... $hour is the hour they selected in the form. $timezone is the time zone selection in the form(it holds values like -2, +4, 0, -3, etc.) And I was using $currenttimezone to get things back to greenwich mean time (that should be +6 not -6), I am 6 hours behind greenwich mean time. Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614740 Share on other sites More sharing options...
unkwntech Posted August 12, 2008 Share Posted August 12, 2008 Do all your calculations against GMT (0) then. $currentTime = gmdate(H);//Timestamp for GMT $timeZone = '-8' //My Time offset - Pacific Cost $eventTime = $currentTime + $timeZone echo $eventTime; If I ran this now it should output 10, as it's 10:35 here, you'll have to expand on it for the minutes, but it's the same process. EDIT: I fixed some logic errors Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614741 Share on other sites More sharing options...
redarrow Posted August 12, 2008 Share Posted August 12, 2008 wouldnt it be better useing the putenv function.............. <?php echo "Original Time: ". date("h:i:s")."\n"; putenv("TZ=US/Eastern"); echo "New Time: ". date("h:i:s")."\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614743 Share on other sites More sharing options...
jakebur01 Posted August 12, 2008 Author Share Posted August 12, 2008 I need to use the unix timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614746 Share on other sites More sharing options...
unkwntech Posted August 12, 2008 Share Posted August 12, 2008 gmdate takes the same parameters as date so change it to gmdate('u') and you will get EPOCH for GMT. Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614752 Share on other sites More sharing options...
jakebur01 Posted August 12, 2008 Author Share Posted August 12, 2008 I have a chat that users can schedule at a given time. In the form they are able to choose timezone, hour, day, and month. I am storing this into my database as a unix time stamp. What is the best way for me to do this? <form name="form1" method="post" action="process_meeting.php"> <table width="614" border="0" cellspacing="3" cellpadding="3"> <tr> <td width="107" class="style23">Type:</td> <td width="222"><select name="select"> <option value="t1">t1</option> <option value="t2">t2</option> <option value="t3">t3</option> <option value="t4">t4</option> <option value="t5">t5</option> </select> </td> </tr> <tr> <td class="style23">Club:</td> <td><input type="text" name="textfield"></td> </tr> <tr> <td class="style23">Topic:</td> <td><input type="text" name="textfield2"></td> </tr> <tr> <td class="style23">Timezone:</td> <td> <select name="timezone"> <option value="-12">GMT - 12 Hours (INTERNATIONAL DATE LINE WEST)</option> <option value="-11">GMT - 11 Hours (NOME TIME)</option> <option value="-10">GMT - 10 Hours (HAWAII/ALASKA STANDARD TIME)</option> <option value="-9">GMT - 9 Hours (ALASKA/YUKON STANDARD TIME)</option> <option value="-8">GMT - 8 Hours (PACIFIC STANDARD TIME-USA-CANADA)</option> <option value="-7">GMT - 7 Hours (MOUNTAIN STANDARD TIME-USA-CANADA)</option> <option value="-6">GMT - 6 Hours (CENTRAL STANDARD TIME-USA-CANADA)</option> <option value="-5">GMT - 5 Hours (EASTERN STANDARD TIME-USA-CANADA)</option> <option value="-4">GMT - 4 Hours (ATLANTIC STANDARD TIME)</option> <option value="-3">GMT - 3 Hours</option> <option value="-2">GMT - 2 Hours (AZORES TIME)</option> <option value="-1">GMT - 1 Hours (WEST AFRICA TIME)</option> <option value="+0">GMT (WESTERN EUROPEAN TIME)</option> <option value="+1">GMT + 1 Hour (CENTRAL EUROPEAN TIME)</option> <option value="+2">GMT + 2 Hours</option> <option value="+3">GMT + 3 Hours</option> <option value="+4">GMT + 4 Hours</option> <option value="+5">GMT + 5 Hours</option> <option value="+6">GMT + 6 Hours</option> <option value="+7">GMT + 7 Hours</option> <option value="+8">GMT + 8 Hours</option> <option value="+9">GMT + 9 Hours</option> <option value="+10">GMT + 10 Hours</option> <option value="+11">GMT + 11 Hours</option> <option value="+12">GMT + 12 Hours</option> </select> </td> </tr> <tr> <td class="style23">Hour:</td> <td><select name=hour> <option value=00>00</option> <option value=01>01</option> <option value=02>02</option> <option value=03>03</option> <option value=04>04</option> <option value=05>05</option> <option value=06>06</option> <option value=07>07</option> <option value=08>08</option> <option value=09>09</option> <option value=10>10</option> <option value=11>11</option> <option value=12>12</option> <option value=13>13</option> <option value=14>14</option> <option value=15>15</option> <option value=16>16</option> <option value=17>17</option> <option value=18>18</option> <option value=19>19</option> <option value=20>20</option> <option value=21>21</option> <option value=22>22</option> <option value=23>23</option> <option value=24>24</option> </select></td> </tr> <tr> <td class="style23">Month:</td> <td><select name=month value=''>Select Month</option> <option value='01'>January</option> <option value='02'>February</option> <option value='03'>March</option> <option value='04'>April</option> <option value='05'>May</option> <option value='06'>June</option> <option value='07'>July</option> <option value='08'>August</option> <option value='09'>September</option> <option value='10'>October</option> <option value='11'>November</option> <option value='12'>December</option> </select> </td> </tr> <tr> <td class="style23">Day:</td> <td><select name=dt > <option value='01'>01</option> <option value='02'>02</option> <option value='03'>03</option> <option value='04'>04</option> <option value='05'>05</option> <option value='06'>06</option> <option value='07'>07</option> <option value='08'>08</option> <option value='09'>09</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25'>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> <option value='31'>31</option> </select></td> </tr> <tr> <td class="style23">Year:</td> <td><span class="style15">Year(yyyy)</span> <input name=year type=text value=2008 size=8 maxlength="4"></td> </tr> </table> <p> <input type="submit" name="Submit" value="Schedule Meeting!"> </p> </form> Now, On the php that processes this... I want it to format it in unix timestamp according to the timezone they selected, hour, month, day, and year. Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614769 Share on other sites More sharing options...
jakebur01 Posted August 12, 2008 Author Share Posted August 12, 2008 What if I want to customize my month, day, year, and hour into this? Say the info from the form is: $year='2008'; $day='23'; $month='8'; $hour='11'; $timezone='-4'; How could I turn this into a unix timestamp? Do all your calculations against GMT (0) then. $currentTime = gmdate(H);//Timestamp for GMT $timeZone = '-8' //My Time offset - Pacific Cost $eventTime = $currentTime + $timeZone echo $eventTime; If I ran this now it should output 10, as it's 10:35 here, you'll have to expand on it for the minutes, but it's the same process. EDIT: I fixed some logic errors Quote Link to comment https://forums.phpfreaks.com/topic/119333-solved-timezone-trouble/#findComment-614781 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.