Aureole Posted January 26, 2008 Share Posted January 26, 2008 Does anyone know of any short and sweet (simple) little functions that accept two parameters: a time-zone and a timestamp and will change the time-zone according to the timestamp. E.g. My server time is EST, my time-zone is GMT. <?php doFunkyStuffWithTimestamp('GMT', '1201341865'); ?> Which would return the time in GMT relative to server-time. I could write one myself but I bet people have needed similar functions a million times before and no doubt someone has already written one. Quote Link to comment https://forums.phpfreaks.com/topic/87891-time-zones/ Share on other sites More sharing options...
Daniel0 Posted January 26, 2008 Share Posted January 26, 2008 How about gmdate()? Quote Link to comment https://forums.phpfreaks.com/topic/87891-time-zones/#findComment-449687 Share on other sites More sharing options...
Aureole Posted January 26, 2008 Author Share Posted January 26, 2008 Never heard of it, I'll go look it up on PHP.net... ??? Quote Link to comment https://forums.phpfreaks.com/topic/87891-time-zones/#findComment-449690 Share on other sites More sharing options...
Aureole Posted January 26, 2008 Author Share Posted January 26, 2008 I just quickly slapped this together: <?php function timezone( $timezone, $timestamp ) { global $output; $timestamp = intval($timestamp); switch( $timezone ) { // (GMT - 12 Hours) Enitwetok, Kwajalien case '-12'; $output = $timestamp - 25200; break; // (GMT - 11 Hours) Midway Island, Samoa case '-11'; $output = $timestamp - 21600; break; // (GMT - 10 Hours) Hawaii case '-10'; $output = $timestamp - 18000; break; // (GMT - 9.5 Hours) French Polynesia case '-9.5'; $output = $timestamp - 16200; break; // (GMT - 9 Hours) Alaska case '-9'; $output = $timestamp - 14400; break; // (GMT - 8 Hours) Pacific Time (US & Canada) case '-8'; $output = $timestamp - 10800; break; // (GMT - 7 Hours) Mountain Time (US & Canada) case '-7'; $output = $timestamp - 7200; break; // (GMT - 6 Hours) Central Time (US & Canada), Mexico City case '-6'; $output = $timestamp - 3600; break; // (GMT - 5 Hours) Eastern Time (US & Canada), Bogota, Lima case '-5'; $output = $timestamp; break; // (GMT - 4 Hours) Atlantic Time (Canada), Caracas, La Paz case '-4'; $output = $timestamp + 3600; break; // (GMT - 3.5 Hours) Newfoundland case '-3.5'; $output = $timestamp + 5400; break; // (GMT - 3 Hours) Brazil, Buenos Aires, Falkland Is. case '-3'; $output = $timestamp + 7200; break; // (GMT - 2 Hours) Mid-Atlantic, Ascention Is., St Helena case '-2'; $output = $timestamp + 10800; break; // (GMT - 1 Hour) Azores, Cape Verde Islands case '-1'; $output = $timestamp + 14400; break; // (GMT) Casablanca, Dublin, London, Lisbon, Monrovia case '0'; $output = $timestamp + 18000; break; // (GMT + 1 Hour) Brussels, Copenhagen, Madrid, Paris case '1'; $output = $timestamp + 21600; break; // (GMT + 2 Hours) Kaliningrad, South Africa case '2'; $output = $timestamp + 25200; break; // (GMT + 3 Hours) Baghdad, Riyadh, Moscow, Nairobi case '3'; $output = $timestamp + 28800; break; // (GMT + 3.5 Hours) Tehran case '3.5'; $output = $timestamp + 30600; break; // (GMT + 4 Hours) Abu Dhabi, Baku, Muscat, Tbilisi case '4'; $output = $timestamp + 32400; break; // (GMT + 4.5 Hours) Kabul case '4.5'; $output = $timestamp + 34200; break; // (GMT + 5 Hours) Ekaterinburg, Karachi, Tashkent case '5'; $output = $timestamp + 36000; break; // (GMT + 5.5 Hours) Bombay, Calcutta, Madras, New Delhi case '5.5'; $output = $timestamp + 37800; break; // (GMT + 5.75 Hours) Kathmandu case '5.75'; $output = $timestamp + 38700; break; // (GMT + 6 Hours) Almaty, Colombo, Dhaka case '6'; $output = $timestamp + 39600; break; // (GMT + 6.5 Hours) Yangon, Naypyidaw, Bantam case '6.5'; $output = $timestamp + 41400; break; // (GMT + 7 Hours) Bangkok, Hanoi, Jakarta case '7'; $output = $timestamp + 43200; break; // (GMT + 8 Hours) Hong Kong, Perth, Singapore, Taipei case '8'; $output = $timestamp + 46800; break; // (GMT + 8.75 Hours) Caiguna, Eucla case '8.75'; $output = $timestamp + 49500; break; // (GMT + 9 Hours) Osaka, Sapporo, Seoul, Tokyo, Yakutsk case '9'; $output = $timestamp + 50400; break; // (GMT + 9.5 Hours) Adelaide, Darwin case '9.5'; $output = $timestamp + 52200; break; // (GMT + 10 Hours) Melbourne, Papua New Guinea, Sydney case '10'; $output = $timestamp + 54000; break; // (GMT + 10.5 Hours) Lord Howe Island case '10.5'; $output = $timestamp + 55800; break; // (GMT + 11 Hours) Magadan, New Caledonia, Solomon Is. case '11'; $output = $timestamp + 57600; break; // (GMT + 11.5 Hours) Burnt Pine, Kingston case '11.5'; $output = $timestamp + 59400; break; // (GMT + 12 Hours) Auckland, Fiji, Marshall Island case '12'; $output = $timestamp + 61200; break; // (GMT + 12.75 Hours) Chatham Islands case '12.75'; $output = $timestamp + 63900; break; // (GMT + 13 Hours) Kamchatka, Anadyr case '13'; $output = $timestamp + 64800; break; // (GMT + 14 Hours) Kiritimati case '14'; $output = $timestamp + 68400; break; } return $output; } ?> I'm just wondering about Daylight Savings, I never really understood them. Quote Link to comment https://forums.phpfreaks.com/topic/87891-time-zones/#findComment-449717 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.