Javascript by Day/Time
- Started
- Last post
- 12 Responses
- dMullins0
@airey: www.asmallorange.com
- spraycan0
javascript no, because time is based on client's computer(the time of the operating system). you need to evaluate the server time.
- ismith0
I personally would do it with PHP, just because I can only imagine eventually you might want do do something more for a restaurant website that would just be easier with some kind of dynamic backend... then again, I've never really gotten down and dirty with JS and something as simple as this might be a pretty good use. How comfortable are you with either?
- dMullins0
I have no need for PHP for anything on this site, other than this one specific idea.
I am comfortable using either PHP or Javascript, as this is likely requires a very base-level understanding of either.
- welded0
Not to necessarily suggest PHP over Javascript but it needn't be any more complex than something like this:
<img src="/images/<?php echo date('l'); ?>.jpg" alt="<?php echo date('l'); ?>" /> (hopefully that code doesn't get mangled...)
Basically you can just have a series of images named 'Monday.jpg', 'Tuesday.jpg', etc. and when your page is parsed it'll just work. You can make it fancier and more complicated, but this'll get the job done with a minimum of fuss.
http://php.net/manual/en/functio…
- nocomply0
you might need something more robust than this, but I've done something similar using javascript to load different CSS files based on the time of day.
Just create a CSS id and assign different background images in each different css file.
- airey0
the other question is, will this be night and day according to the business timezone or the viewing browser? obviously if it's a simple script it will just look at the users computer / browser time and give that graphic whereas a more comprehensive solution will base the look on a specific timezone running on the hosting server.
- Would need it to be defined based on business timezone.dMullins
- acescence0
javascript date and time can be wrong if the user's computer's time or date are wrong.
- welded0
I don't know off hand if you can define the timezone in JS, but here's how you'd do it with PHP (because otherwise all date functions will use the server time):
date_default_timezone_set('Ameri...
http://www.php.net/manual/en/fun…
http://www.php.net/manual/en/tim…
- acescence0
i think php is more efficient overall, you get the page served up as it should be from the server, rather than page load > script load > script execute > image fetch > page render complete
- airey0
srry to hijack but can someone recommend a decent host for a client? i use mediatemple and can't refer clients to them anymore. something with good admin tools (like the mt ones), dns and database control as well as multiple domains under the one account. thx in advance.
- DreamHost is fine.welded
- fatcow.comutopian
- free.frspraycan
- fugged0
Just make sure that when you get the time on the server, that you get UTC time. Then subtract/add the appropriate amount for the time-zone that the business is located in. Then then your code will work regardless of what time zone the server is in.
- Or do as I suggest and set the timezone at runtime.welded