Timezone script [PHP]

Discussion in 'PHP' started by Javver, Dec 27, 2007.

  1. #1
    hello every1,

    how can i create a php script that displays the current time of a timezone [ex. EST or WET] with seconds, date, day and am/pm. Please give me a sample script.

    Thanks and Merry Xmas,
    Archie
     
    Javver, Dec 27, 2007 IP
  2. zantarm

    zantarm Banned

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you still want this script?
     
    zantarm, Dec 27, 2007 IP
  3. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #3
    Its easy :)

    Just replace those inside quotes to print what you want. Refer this
     
    olddocks, Dec 27, 2007 IP
  4. Javver

    Javver Active Member

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    can some1 give a sample script that displays live seconds, date, day and am or pm
     
    Javver, Dec 27, 2007 IP
  5. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #5
    Refer this & review the agruments, usage carefully, comments also
     
    temp2, Dec 27, 2007 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    All you need to do for a timezone script is use the unix timestamp.

    Then all you would need to do is state which time zones there are within a drop down menu.

    GMT1 would be time() + 3600;

    The list would go on like that. Simple.
     
    HuggyStudios, Dec 27, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  8. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    A JavaScript solution:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title> World Clock </title>
    <script type="text/javascript">
    
    	var GMToffset = -5; // Your CURRENT local GMT offset, whether Daylight or Standard
    	var localDST = false;  // true if you are currently using Daylight time
    	
    	var cityOffset = [];  // GMT Offsets are Standard Time for that location
    	cityOffset[1] = 1;      
    	cityOffset[2] = 10;        
    	cityOffset[3] = -10;      
    
    	var zoneDate = "";
    	
    	function update(i){
    
    		var PM = false;
    		document.getElementById('cityDay'+i).lastChild.data = zoneDate.toString().substring(0,3);
    		document.getElementById('cityDate'+i).lastChild.data = zoneDate.getDate()+" "+zoneDate.toString().substring(4,7)+" "+zoneDate.getFullYear();
    		var nHours = zoneDate.getHours().toString();
    		var nMins = zoneDate.getMinutes().toString();
    		if (nMins < 10){nMins = "0"+nMins}
    		if (nHours > 12){nHours = nHours-12; PM=true}
    		var timeStr =  nHours+":"+nMins;
    		if (PM){timeStr += " PM"} 
    		if (!PM && nHours != 12){timeStr += " AM"}
    		if (!PM && nHours == 12){timeStr += " PM"}
    		if (!PM && nHours == 0){timeStr = timeStr.replace(/0:/,"12:")}
    		document.getElementById('cityTime'+i).lastChild.data = timeStr;
    		if (localDST){document.getElementById('dispDST').lastChild.data = 'Yes'}
    		else {document.getElementById('dispDST').lastChild.data = 'No'}
    	}
    
    	function dispClocks(){
    
    		document.getElementById('localMsg').lastChild.data = "Local Time GMT "+GMToffset;
    		var PM = false;
    		var index = "";
    		var refDate = new Date();
    		refDate.setHours(GMToffset+refDate.getHours()+refDate.getTimezoneOffset()/60);
    		document.getElementById('localDay').lastChild.data = refDate.toString().substring(0,3);
    		document.getElementById('localDate').lastChild.data = refDate.getDate()+" "+refDate.toString().substring(4,7)+" "+refDate.getFullYear();
    		var nHours = refDate.getHours().toString();
    		var nMins = refDate.getMinutes().toString();
    		if (nMins < 10){nMins = "0"+nMins}
    		if (nHours > 12){nHours = nHours-12; PM=true}
    		var timeStr =  nHours+":"+nMins;
    		if (PM){timeStr += " PM"} 
    		if (!PM && nHours != 12){timeStr += " AM"}
    		if (!PM && nHours == 12){timeStr += " PM"}
    		if (!PM && nHours == 0){timeStr = timeStr.replace(/0:/,"12:")}
    		document.getElementById('localTime').lastChild.data = timeStr;
    		for (i=1; i<cityOffset.length; i++)
    			{
    			 index = cityOffset[i];
    			 if (document.getElementById('DST'+i).checked){index++}
    			 zoneDate = new Date();
    			 zoneDate.setHours(index+zoneDate.getHours()+zoneDate.getTimezoneOffset()/60);
    			 update(i);
    			}
    		setTimeout("dispClocks()",60000);
    	}
    
    	onload=dispClocks;
    
    </script>
    <style type="text/css">
    
    	body {margin-top: 50px}
    
    </style>
    </head>
    <body>
          <table align='center' border='1' cellspacing='0' cellpadding='5' style='font-size:11pt;background-color:#ffffe0'>
             <thead style='background-color:#ffe4b5'>
                <tr>
                   <th>
                      Location
                   </th>
                   <th>
                      Day
                   </th>
                   <th>
                      Date
                   </th>
                   <th>
                      Time
                   </th>
                   <th>
                      DST
                   </th>
                </tr>
             </thead>
             <tfoot>
                <tr>
                   <td id='localMsg' colspan='5' align='center' style='font-size:8pt;background-color:#90ee90;padding:1px'>
                      &nbsp;
                   </td>
                </tr>
             </tfoot>
             <tbody>
                <tr style='background-color:#90ee90'>
                   <td>
                      New York
                   </td>
                   <td id='localDay' align='center'>
                      &nbsp;
                   </td>
                   <td id='localDate' align='center'>
                      &nbsp;
                   </td>
                   <td id='localTime' align='center'>
                      &nbsp;
                   </td>
                   <td id='dispDST' align='center'>
                      &nbsp;
                   </td>
                </tr>
                <tr>
                   <td>
                      Madrid
                   </td>
                   <td id='cityDay1' align='center'>
                      &nbsp;
                   </td>
                   <td id='cityDate1' align='center'>
                      &nbsp;
                   </td>
                   <td id='cityTime1' align='center'>
                      &nbsp;
                   </td>
                   <td align='center'>
                      <input type='checkbox' id='DST1' onclick="dispClocks()" disabled>
                   </td>
                </tr>
                <tr>
                   <td>
                      Sydney
                   </td>
                   <td id='cityDay2' align='center'>
                      &nbsp;
                   </td>
                   <td id='cityDate2' align='center'>
                      &nbsp;
                   </td>
                   <td id='cityTime2' align='center'>
                      &nbsp;
                   </td>
                   <td align='center'>
                      <input type='checkbox' id='DST2' onclick="dispClocks()" checked disabled>
                   </td>
                </tr>
                <tr>
                   <td>
                      Honolulu
                   </td>
                   <td id='cityDay3' align='center'>
                      &nbsp;
                   </td>
    
                   <td id='cityDate3' align='center'>
                      &nbsp;
                   </td>
                   <td id='cityTime3' align='center'>
                      &nbsp;
                   </td>
                   <td align='center'>
                      <input type='checkbox' id='DST3' onclick="dispClocks()" disabled>
                   </td>
                </tr>
             </tbody>
          </table>
    </html>
    
    Code (markup):
     
    Mike H., Dec 28, 2007 IP
  9. Javver

    Javver Active Member

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #9
    I want to display this for example :

    January 04, 2006 Thurs 07:00 am New York
    January 04, 2006 Thurs 00:00 am Country
    January 04, 2006 Thurs 00:00 am Country

    i want to do it by timezone
     
    Javver, Jan 3, 2008 IP