Jump to content

Calculating world time in php?


PHPnewby!

Recommended Posts

Hi guys,

 

I'm looking at calculating world time in php, but not really sure where to start?

 

I imagine that this would require a msql database table containing 2 columns..country and the time difference from the UK?

 

Hoping to allow users to select a country from a drop down menu in order to display the current time in that country, based upon the time in the UK...

 

Has anyone got any tips to get me started? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/36755-calculating-world-time-in-php/
Share on other sites

you will need to achieve that by adding the time difference as strtotime, this is extracted from part of my page:

$timezones = array(
		'-25200' => 'International Date Line (West) GMT-12',
		'-21600' => 'Midway Island, Samoa GMT-11',
		'-18000' => 'Hawaii, Honolulu GMT-10',
		'-14400' => 'Alaska GMT-9',
		'-10800' => 'Pacific Standard Time, US, Canada GMT-8',
		'-7200' => 'British Columbia N.E., Santa Fe, Mountain Time GMT-7',
		'-3600' => 'Central America, Chicago, Guatamala, Mexico City GMT-6',
		'0' => 'US, Canada, Bogota, Boston, New York GMT-5',
		'+3600' => 'Canada, Santiago, Atlantic Standard Time GMT-4',
		'+7200' => 'Brazilia, Buenos Aires, Georgetown, Greenland GMT-3',
		'+10800' => 'Mid-Atlantic GMT-2',
		'+14400' => 'Azores, Cape Verde Is., Western Africa Time GMT-1',
		'+18000' => 'London, Iceland, Ireland, Morocco, Portugal GMT',
		'+21600' => 'Amsterdam, Berlin, Bern, Madrid, Paris, Rome, GMT+1',
		'+25200' => 'Athens, Cairo, Cape Town, Finland, Greece, Israel GMT+2',
		'+28800' => 'Ankara, Aden, Baghdad, Beruit, Kuwait, Moscow GMT+3',
		'+32400' => 'Abu Dhabi, Baku, Kabul, Tehran, Tbilisi, Volgograd GMT+4',
		'+36000' => 'Calcutta, Colombo, Islamabad, Madras, New Dehli GMT+5',
		'+39600' => 'Almaty, Dhakar, Kathmandu, Colombo, Sri Lanka GMT+6',
		'+43200' => 'Bangkok, Hanoi, Jakarta, Phnom Penh, Australia GMT+7',
		'+46800' => 'Taipei, Beijing, Hong Kong, Singapore, GMT+8',
		'+50400' => 'Seoul, Tokyo, Central Australia GMT+9',
		'+54000' => 'Brisbane, Canberra, Guam, Melbourne, Sydney, GMT+10',
		'+57600' => 'Magadan, New Caledonia, Solomon Is. GMT+11',
		'+61200' => 'Auckland, Fiji, Kamchatka, Marshall, Wellington, GMT+12',);

this gives the different timezones as the main cities, however, is not in reference to UK time, you have to change it to suit you. because my host uses US time. what you do is:

$localtime = $strtotime("now") + $time;//$time is the figures from above^^^

Hope that helps you

Ted

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.