Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Universal Time Script.

Featured Replies

I have designed an internet radio website, it airs from 5PM 'til 9PM GMT on saturdays and sundays.

 

I would like a script or something that when somebody from a different country goes on the website it shows the airing times/days in their timezones. I am NOT looking for a countdown script.

I have designed an internet radio website, it airs from 5PM 'til 9PM GMT on saturdays and sundays.

 

I would like a script or something that when somebody from a different country goes on the website it shows the airing times/days in their timezones. I am NOT looking for a countdown script.

Just use the built in date functions in php they have where u can use UTC to

More importantly, From your Display Picture you look quite young, and looking at your age on your profile I see i've just confirmed my suspicions. Seen as this "radio" thing does seem to be the latest fad amongst teenage scripties - Though strangely has lasted a good 3 or 4 years, but because of your age you may not be aware of this, but, if you're airing music (Which I might add, Copyrighted Music) then you need to have a radio license. Without one, you're committing a criminal offense and are a pirate radio. You could end up in a lot of trouble with the police and more seriously, you could find your self with a civil prosecution against yourself if you get sued by the music companies.

More importantly, From your Display Picture you look quite young, and looking at your age on your profile I see i've just confirmed my suspicions. Seen as this "radio" thing does seem to be the latest fad amongst teenage scripties - Though strangely has lasted a good 3 or 4 years, but because of your age you may not be aware of this, but, if you're airing music (Which I might add, Copyrighted Music) then you need to have a radio license. Without one, you're committing a criminal offense and are a pirate radio. You could end up in a lot of trouble with the police and more seriously, you could find your self with a civil prosecution against yourself if you get sued by the music companies.

 

Was just about to post this. If in the UK you'll need two types of licenses. The right to broadcast copyrighted music in the UK is very pricey (especially online.)

 

In the UK see: http://www.mcps-prs.com

  • Author

More importantly, From your Display Picture you look quite young, and looking at your age on your profile I see i've just confirmed my suspicions. Seen as this "radio" thing does seem to be the latest fad amongst teenage scripties - Though strangely has lasted a good 3 or 4 years, but because of your age you may not be aware of this, but, if you're airing music (Which I might add, Copyrighted Music) then you need to have a radio license. Without one, you're committing a criminal offense and are a pirate radio. You could end up in a lot of trouble with the police and more seriously, you could find your self with a civil prosecution against yourself if you get sued by the music companies.

 

 

Was just about to post this. If in the UK you'll need two types of licenses. The right to broadcast copyrighted music in the UK is very pricey (especially online.)

 

In the UK see: http://www.mcps-prs.com

 

We play indie artists that we have permission for (:

Were smarter than you think haha.

 

We were looking into getting a license but the budget doesnt stretch that far I'm afraid :/

  • Author

Just use the built in date functions in php they have where u can use UTC to

 

Could you expand on this? I'm a noob at PHP :blink:

We play indie artists that we have permission for (:

Were smarter than you think haha.

 

We were looking into getting a license but the budget doesnt stretch that far I'm afraid :/

 

Not necessarily smarter. We're more than anything making sure you know what direction you're heading in and the risks involved, but if you have permission then that's great.

This is to display the current time:

 

<?php echo date("g:i a"); ?>

 

Learn more about the date function, and how to format it here.

This is to display the current time:

 

<?php echo date("g:i a"); ?>

 

Learn more about the date function, and how to format it here.

 

 

I don't think that's enough. All that will do is display the time locally, so if someone happens to open the radio site when the radio is playing, it will show the local time.

 

However, if you want to show the times that the radio will be on air in text form, and the internet radio is on from 5pm to 9pm GMT that has to be converted to the PHP GMT date format and then converted to the local time so that it will show 5pm to 9pm GMT in the local time.

 

If the internet radio is on from 5pm to 9pm British Summer Time that has to be converted to GMT and then that has to be converted to the PHP GMT date format and then converted to the local time.

 

Or the PHP has to compare the local computer's time with GMT and add or subtract the necessary number of hours.

 

If someone takes their laptop to stay with a friend the other side of America, how does the computer know that the time zone has changed?

 

My PHP isn't good enough.

I don't think that's enough. All that will do is display the time locally, so if someone happens to open the radio site when the radio is playing, it will show the local time.

 

However, if you want to show the times that the radio will be on air in text form, and the internet radio is on from 5pm to 9pm GMT that has to be converted to the PHP GMT date format and then converted to the local time so that it will show 5pm to 9pm GMT in the local time.

 

If the internet radio is on from 5pm to 9pm British Summer Time that has to be converted to GMT and then that has to be converted to the PHP GMT date format and then converted to the local time.

 

Or the PHP has to compare the local computer's time with GMT and add or subtract the necessary number of hours.

 

If someone takes their laptop to stay with a friend the other side of America, how does the computer know that the time zone has changed?

 

My PHP isn't good enough.

 

Uhh, I simply wanted to show him a little bit of which direction to go in, and let him try and solve it himself. Of course you can overwrite the timezone like this:

 

date_default_timezone_set('America/New_York');

 

Here is a complete list of timezones.

 

In the end, your code may look something like this:

 

<?php
// Set the default timezone
date_default_timezone_set('America/New_York');

// Display the time according to the timezone
echo date(g:i a);

?>

 

And to answer your question Wickham, the laptop gets the appropriate timezone by fetching it from the local ISP servers. Notice if you don't have access to the internet, you will have to adjust the time manually.

  • Author

Ok thanks for the code, but I added the following to my .php page

 

Airing every saturday and sunday from <?php date_default_timezone_set('Europe/London'); echo date(5:00 pm); ?> 'til <?php date_default_timezone_set('Europe/London'); echo date(9:00 pm); ?>

 

But it just prevented the page from loading, any ideas why this has happened?

The date function will show the servers local time. Not the user viewing.

 

// Set locale. (en_UK for this example)
setlocale(LC_TIME, 'en_UK');

// Time plus 1 hour.
$plus_hour  =  time() + 3600;
echo strftime('%A %e %B %Y',$plus_hour);

 

Find categories here:

http://www.w3.org/WAI/ER/IG/ert/iso639.htm

 

PHP manual:

http://www.php.net/manual/en/function.setlocale.php

I'm also interested in the answer to this and I don't think it's been given yet.

 

CBG wants text on a computer in UK GMT (winter time) to say:-

Airing every saturday and sunday from 5:00 pm 'til 9:00 pm.

 

and on someone's computer in Brisbane Australia:-

Airing every sunday and monday from 3:00 am 'til 7:00 am.

 

because Brisbane is 10 hours ahead of GMT and it will be the next day.

 

Remember that the person in Brisbane may have an ISP's server in Perth where the time zone is only 8 hours ahead of GMT, different from his computer, so you can't use the server time, it has to make an adjustment from the actual computer's time.

After an in-depth discussion with Google, I conclude that;

This can be done using Javascript, but is impossible using PHP. PHP is serverside script, Javascript is client side.

The best you can do with PHP is an IP to geographical location lookup, but this won't guarantee success.

 

Again, this conclusion is drawn up from results of my Google searches - I'm not sure it's 100% accurate.

Agreed, I've found this:-

http://www.webmasterworld.com/forum13/3922.htm

 

but the viewer's IP address may be in a different time zone.

 

Also

http://www.onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/

 

I would leave it to the viewer to work it out from GMT!

You may want to build a tiny php app with a dropdown where you select your country, and based on that it will take the airing time (5-9pm) and then perform the math function associated with the country, whether its +10 or -5.

  • Author

You may want to build a tiny php app with a dropdown where you select your country, and based on that it will take the airing time (5-9pm) and then perform the math function associated with the country, whether its +10 or -5.

 

Ahh! Now that would be good! I will look into that.

Hey, let me know if I can help!

 

I can even agree to do this for you, if I could then blog about it.

 

Thanks!

GeoIP is very accurate country wise, however, the best bet would be a dropdown.

 

This is a basic example - lets say on index.php we ask for a users timezone. If they have set it before we'll redirect them to homepage.php, if they haven't ask them to specify it and set it as a cookie with a length of a YEAR.

 

<?php
$timeDiff       =       (isset($_POST['timeDiff'])) ? $_POST['timeDiff'] : FALSE;

// They've already specified their time difference/zone
if (isset($_COOKIE['timeDiff']))
{
       Header('Location: homepage.php');
       exit();
}

if ($timeDiff)
{
       // Set a cookie for a year.
       setcookie('timeDiff', $timeDiff, time()+31536000);

       // Redirect.
       Header('Location: homepage.php');
       exit();
}
?>

<form action="" method="post">
<p>Please set your timezone: </p>
<select name="timeDiff">
	  <option value="-12.0">(GMT -12:00) Eniwetok, Kwajalein</option>
	  <option value="-11.0">(GMT -11:00) Midway Island, Samoa</option>
	  <option value="-10.0">(GMT -10:00) Hawaii</option>
	  <option value="-9.0">(GMT -9:00) Alaska</option>
	  <option value="-8.0">(GMT -8:00) Pacific Time (US & Canada)</option>
	  <option value="-7.0">(GMT -7:00) Mountain Time (US & Canada)</option>
	  <option value="-6.0">(GMT -6:00) Central Time (US & Canada), Mexico City</option>
	  <option value="-5.0">(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima</option>
	  <option value="-4.0">(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
	  <option value="-3.5">(GMT -3:30) Newfoundland</option>
	  <option value="-3.0">(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
	  <option value="-2.0">(GMT -2:00) Mid-Atlantic</option>
	  <option value="-1.0">(GMT -1:00 hour) Azores, Cape Verde Islands</option>
	  <option value="0.0">(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
	  <option value="1.0">(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
	  <option value="2.0">(GMT +2:00) Kaliningrad, South Africa</option>
	  <option value="3.0">(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
	  <option value="3.5">(GMT +3:30) Tehran</option>
	  <option value="4.0">(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
	  <option value="4.5">(GMT +4:30) Kabul</option>
	  <option value="5.0">(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
	  <option value="5.5">(GMT +5:30) Bombay, Calcutta, Madras, New Delhi</option>
	  <option value="5.75">(GMT +5:45) Kathmandu</option>
	  <option value="6.0">(GMT +6:00) Almaty, Dhaka, Colombo</option>
	  <option value="7.0">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
	  <option value="8.0">(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
	  <option value="9.0">(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
	  <option value="9.5">(GMT +9:30) Adelaide, Darwin</option>
	  <option value="10.0">(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
	  <option value="11.0">(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
	  <option value="12.0">(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
</select>
<input type="submit" name="submit" value="continue" />
</form>

 

On homepage.php we'll then display the time to them based off of GMT.

 

$timeDiff = (isset($_COOKIE['timeDiff'])) ? $_COOKIE['timeDiff'] : 0.0;

$timeDiff = $timeDiff * 3600; // Into hours.
echo 'Current date/time for you is: '.gmdate('m/d/Y g:i:s A', time()+$timeDiff);

 

This is a very basic implementation and needs a few tweaks.

 

 

 

(dropdown taken from: http://www.michaelapproved.com/articles/timezone-dropdown-select-list/)

GeoIP is very accurate country wise, however, the best bet would be a dropdown.

 

This is a basic example - lets say on index.php we ask for a users timezone. If they have set it before we'll redirect them to homepage.php, if they haven't ask them to specify it and set it as a cookie with a length of a YEAR.

 

<?php
$timeDiff       =       (isset($_POST['timeDiff'])) ? $_POST['timeDiff'] : FALSE;

// They've already specified their time difference/zone
if (isset($_COOKIE['timeDiff']))
{
       Header('Location: homepage.php');
       exit();
}

if ($timeDiff)
{
       // Set a cookie for a year.
       setcookie('timeDiff', $timeDiff, time()+31536000);

       // Redirect.
       Header('Location: homepage.php');
       exit();
}
?>

<form action="" method="post">
<p>Please set your timezone: </p>
<select name="timeDiff">
	  <option value="-12.0">(GMT -12:00) Eniwetok, Kwajalein</option>
	  <option value="-11.0">(GMT -11:00) Midway Island, Samoa</option>
	  <option value="-10.0">(GMT -10:00) Hawaii</option>
	  <option value="-9.0">(GMT -9:00) Alaska</option>
	  <option value="-8.0">(GMT -8:00) Pacific Time (US & Canada)</option>
	  <option value="-7.0">(GMT -7:00) Mountain Time (US & Canada)</option>
	  <option value="-6.0">(GMT -6:00) Central Time (US & Canada), Mexico City</option>
	  <option value="-5.0">(GMT -5:00) Eastern Time (US & Canada), Bogota, Lima</option>
	  <option value="-4.0">(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz</option>
	  <option value="-3.5">(GMT -3:30) Newfoundland</option>
	  <option value="-3.0">(GMT -3:00) Brazil, Buenos Aires, Georgetown</option>
	  <option value="-2.0">(GMT -2:00) Mid-Atlantic</option>
	  <option value="-1.0">(GMT -1:00 hour) Azores, Cape Verde Islands</option>
	  <option value="0.0">(GMT) Western Europe Time, London, Lisbon, Casablanca</option>
	  <option value="1.0">(GMT +1:00 hour) Brussels, Copenhagen, Madrid, Paris</option>
	  <option value="2.0">(GMT +2:00) Kaliningrad, South Africa</option>
	  <option value="3.0">(GMT +3:00) Baghdad, Riyadh, Moscow, St. Petersburg</option>
	  <option value="3.5">(GMT +3:30) Tehran</option>
	  <option value="4.0">(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi</option>
	  <option value="4.5">(GMT +4:30) Kabul</option>
	  <option value="5.0">(GMT +5:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
	  <option value="5.5">(GMT +5:30) Bombay, Calcutta, Madras, New Delhi</option>
	  <option value="5.75">(GMT +5:45) Kathmandu</option>
	  <option value="6.0">(GMT +6:00) Almaty, Dhaka, Colombo</option>
	  <option value="7.0">(GMT +7:00) Bangkok, Hanoi, Jakarta</option>
	  <option value="8.0">(GMT +8:00) Beijing, Perth, Singapore, Hong Kong</option>
	  <option value="9.0">(GMT +9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk</option>
	  <option value="9.5">(GMT +9:30) Adelaide, Darwin</option>
	  <option value="10.0">(GMT +10:00) Eastern Australia, Guam, Vladivostok</option>
	  <option value="11.0">(GMT +11:00) Magadan, Solomon Islands, New Caledonia</option>
	  <option value="12.0">(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka</option>
</select>
<input type="submit" name="submit" value="continue" />
</form>

 

On homepage.php we'll then display the time to them based off of GMT.

 

$timeDiff = (isset($_COOKIE['timeDiff'])) ? $_COOKIE['timeDiff'] : 0.0;

$timeDiff = $timeDiff * 3600; // Into hours.
echo 'Current date/time for you is: '.gmdate('m/d/Y g:i:s A', time()+$timeDiff);

 

This is a very basic implementation and needs a few tweaks.

 

 

 

(dropdown taken from: http://www.michaelapproved.com/articles/timezone-dropdown-select-list/)

 

 

Exactly what I was gonna do. Nice job!

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.