Hello Visitor
Here is a example how we can set time zone in php.Time zone functionally is very important in auction sites, freelance based sites, product base sites, but many programmer don’t care about time zone.
due to this lake of programming visitor face problems and sites goes to down.
Here is an example how we can solve time zone issue according to
PHP script.

Example – Suppose you are from India and you submit a product in auction bases site, you insert end date of product according to Indian time zone but server is in UK, then automatically the end date of product will be on UK time zone( insert in mysql). but it must be show for you in Indian time zone, anybody viewing this product will show on their < country own time zone not UK based data and time. So for this PHP Provide a solution. 1-Create a table

`timezid` int(11) NOT NULL auto_increment,
`tz` varchar(250) NOT NULL default ”,
`gmt` text NOT NULL,
PRIMARY KEY (`timezid`)

INSERT INTO `timezone` (`timezid`, `tz`, `gmt`) VALUES
(1, ‘Pacific/Kwajalein’, ‘(GMT -12:00) Eniwetok, Kwajalein’),
(2, ‘Pacific/Samoa’, ‘(GMT -11:00) Midway Island, Samoa’),
(3, ‘Pacific/Honolulu’, ‘(GMT -10:00) Hawaii’),
(4, ‘America/Anchorage’, ‘(GMT -9:00) Alaska’),
(5, ‘America/Los_Angeles’, ‘(GMT -8:00) Pacific Time (US & Canada) Los Angeles, Seattle’),
(6, ‘America/Denver’, ‘(GMT -7:00) Mountain Time (US & Canada) Denver’),
(7, ‘America/Chicago’, ‘(GMT -6:00) Central Time (US & Canada), Chicago, Mexico City’),
(8, ‘America/New_York’, ‘(GMT -5:00) Eastern Time (US & Canada), New York, Bogota, Lima’),
(9, ‘Atlantic/Bermuda’, ‘(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz’),
(10, ‘Canada/Newfoundland’, ‘(GMT -3:30) Newfoundland’),
(11, ‘Brazil/East’, ‘(GMT -3:00) Brazil, Buenos Aires, Georgetown’),
(12, ‘Atlantic/Azores’, ‘(GMT -2:00) Mid-Atlantic’),
(13, ‘Atlantic/Cape_Verde’, ‘(GMT -1:00 hour) Azores, Cape Verde Islands’),
(14, ‘Europe/London’, ‘(GMT) Western Europe Time, London, Lisbon, Casablanca’),
(15, ‘Europe/Brussels’, ‘(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris’),
(16, ‘Europe/Helsinki’, ‘(GMT +2:00) Kaliningrad, South Africa’),
(17, ‘Asia/Baghdad’, ‘(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg’),
(18, ‘Asia/Tehran’, ‘(GMT +3:30) Tehran’),
(19, ‘Asia/Baku’, ‘(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi’),
(20, ‘Asia/Kabul’, ‘(GMT +4:30) Kabul’),
(21, ‘Asia/Karachi’, ‘(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent’),
(22, ‘Asia/Calcutta’, ‘(GMT +5:30) Bombay, Calcutta, Madras, New Delhi’),
(23, ‘Asia/Dhaka’, ‘(GMT +6:00) Almaty, Dhaka, Colombo’),
(24, ‘Asia/Bangkok’, ‘(GMT +7:00) Bangkok, Hanoi, Jakarta’),
(25, ‘Asia/Hong_Kong’, ‘(GMT +8:00) Beijing, Perth, Singapore, Hong Kong’),
(26, ‘Asia/Tokyo’, ‘(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk’),
(27, ‘Australia/Adelaide’, ‘(GMT +9:30) Adelaide, Darwin’),
(28, ‘Pacific/Guam’, ‘(GMT +10:00) Eastern Australia, Guam, Vladivostok’),
(29, ‘Asia/Magadan’, ‘(GMT +11:00) Magadan, Solomon Islands, New Caledonia’),
(30, ‘Pacific/Fiji’, ‘(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka’);

This table contain all countries timezone parameter.

2-PHP function

  1. function getCorrectTime($date_time_string, $tz, $date_format = “r”) {
  2. $time = strtotime($date_time_string);
  3. $tz_bak = getenv(“TZ”);
  4. putenv(“TZ=$tz”);
  5. $validdate= date($date_time_string, $time);
  6. putenv(“TZ” . ($tz_bak ? “=$tz_bak” : “”));
  7. return $validdate;
  8. }

$date_time_string is inserted date/datetime in database.

$tz is the time zone value from database like Asia/Calcutta for INDIA

$date_format is date/datetime format in which format you want.


$date=’2009-06-29 11:02′ // value from data base

$timezone=’Asia/Calcutta’; // you want indian time zone

$format=’F d,Y H:i a’ // give format of date and time in which format you want date and time

eXTReMe Tracker