display a day and time in localized timezone, in text, a fixed day/time |
display a day and time in localized timezone, in text, a fixed day/time |
bluffwood |
Dec 31 2016, 07:33 AM
Post
#1
|
Group: Members Posts: 6 Joined: 31-December 16 Member No.: 24,986 |
I produce radio shows, that are streamed on multiple outlets at various times. I'd like to list of schedule of when people can tune in. These are not podcasts but live feeds of streaming radio stations.
For example, my show runs 5 times on the weekend. Saturday Noon CT on station A Sunday 7am MT on station B Sunday Noon MT on station C Sunday 9pm ET on Station D Sunday 9pm MT on Station E It's the same times week to week, so I don't want a date, just a day and time. I'd like the user to see these fixed days/times in their local timezone All of the streaming stations (so far) participate in Daylight saving time (US/Northern hemisphere) but that won't likely be the case for much longer. It would be nice if the displays of this schedule took DST of the source and the local listener into account. So if the viewer is in Eastern Time, it would read: Saturday 1pm ET on station A Sunday 9am ET on station B Sunday 2pm ET on station C Sunday 9pm ET on Station D Sunday 11pm ET on Station E and a viewer in Pacific time would read: Saturday 10am PT on station A Sunday 6am PT on station B Sunday 11am PT on station C Sunday 6pm PT on Station D Sunday 8pm PT on Station E this will just display in a cell in an html table. Thanks, in advance, for your help. |
Christian J |
Dec 31 2016, 08:04 AM
Post
#2
|
. Group: WDG Moderators Posts: 9,628 Joined: 10-August 06 Member No.: 7 |
With a server-side script (e.g. PHP) you can get the time set on the radio show's web server. Next, with javascript you can get the time set on the user's own computer, and by adding/subtracting those two time values find out the time difference.
|
bluffwood |
Dec 31 2016, 09:18 PM
Post
#3
|
Group: Members Posts: 6 Joined: 31-December 16 Member No.: 24,986 |
With a server-side script (e.g. PHP) you can get the time set on the radio show's web server. Next, with javascript you can get the time set on the user's own computer, and by adding/subtracting those two time values find out the time difference. it's much simpler than that. I'll hand code the day/time in whatever form a script can convert them to "user time" just need a real simple script. |
pandy |
Jan 1 2017, 11:54 AM
Post
#4
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
Will JavaScript suffice?
If I've understood this half right it should be really simple, but it isn't. This is what we SHOULD be able to do, take a UTC time and convert it to local time, but it doesn't work in (most?) browsers. CODE var airTime = new Date('2016-01-01 17:00:00 UTC'); var localAirTime = airTime.toLocaleString(); alert(localAirTime); toString() automatially converts to local date but JavaScript chokes on the date format. Because of this problem there's a lot of JavaScript time libraries around. You can google for that. I discovered that it works just fine if you convert the date and time to epoch time. https://en.wikipedia.org/wiki/Unix_time You do that with getTime(). Then you can get it back to a normal time format in different ways. You want the user's local date and time, so you could either use toString() which will produce the standard format or you could use toLocaleString() which will produce the format the user has chosen for his machine. Note that you need to use UTC and not your local time for the airing times! CODE var airTimeUTC = new Date("January 1, 2017 17:00:00 UTC"); var airTimeEpoch = airTimeUTC.getTime(); var localAirTime = new Date(airTimeEpoch); alert(localAirTime.toString() + '\n' + localAirTime.toLocaleString()); I set the time to the next whole hour (at the time of writing). I'm in Sweden (GMT +1) and I get the below result. The second line is my preferred format and the first the standard one. If you want to format it another way you can do so by picking the time and date apart with getHours(), getMinutes() and so on. CODE Sun Jan 01 2017 18:00:00 GMT+0100 (Romance Standard Time) 2017-01-01 18:00:00 If you want to use this for something else, note that epoch time is in seconds, but JavaScript uses milliseconds for some reason, so often one needs to calculate with a factor 1000, but that isn't needed here. Also, when I needed this I googled long and hard and didn't find this solution anywhere. I can't think I'm the only one who has thought of this since it's so very simple, so there may be something fishy with it. On the other hand, then I should have found something about the fishiness but I didn't do that either. Anyway, it has worked for me. |
Lo-Fi Version | Time is now: 19th March 2024 - 04:08 AM |