Jump to content

Time-zones...


Aureole

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.