Time based greatings


This is a easy tutorial, basically as easy as the hello world tutorial! Not sure if anybody knows how to do this, so here you guys go:

JavaScript Code
  1. <script type='text/javascript'>
  2. var date=new Date(); // Gets the full date!
  3. var day=date.getHours(); // Gets the hours!
  4.  
  5. if(day<=11) {
  6. document.write('Good Morning'); // If it's before 12 PM then display this!
  7. } else if(day<18){
  8. document.write('Good Afternoon'); // After 12 PM display this!
  9. } else {
  10. document.write('Good Evening'); // After 6 PM display this!
  11. }
  12. </script>


Basically the code does what the comments. Say, it checks if the hour is before 12 PM on the users computer, and if it is then it will display Good Morning, and so on.

Hope this helped!
Diablosblizz's Avatar
Views:
3,021
Rating:
Posted on Wednesday 7th May 2008 at 01:27 AM
DjMilez
DjMilez's Avatar
Great, thanks. I'm using it now.
Posted on Saturday 29th December 2007 at 07:48 PM
Diablosblizz
Diablosblizz's Avatar
But that takes more work, Shadow.
Posted on Saturday 22nd December 2007 at 09:57 PM
ShadowMage
ShadowMage's Avatar
even if PHP is server side, you can use set_default_timezone function or w/e in PHP to get the users timezone time.
Posted on Thursday 20th December 2007 at 04:12 PM
DanielXP
DanielXP's Avatar
Good point Diablosblizz, js would be better on this than php.
Posted on Thursday 20th December 2007 at 11:42 AM
ShadowMage
ShadowMage's Avatar
The one i got on one of my sites is using php with local time
Posted on Thursday 20th December 2007 at 03:04 AM
Diablosblizz
Diablosblizz's Avatar
Oliver, for PHP it would be the servers time, wouldn't it? Javascript is local, so it would get the users time.
Posted on Tuesday 18th December 2007 at 11:14 AM
Oliver
Oliver's Avatar
Yeah but here on RMB I used PHP :P

Oliver
Posted on Saturday 15th December 2007 at 09:43 PM
Diablosblizz
Diablosblizz's Avatar
Like I said, it's basically as easy as the hello world tutorial! :P
Posted on Saturday 15th December 2007 at 07:36 PM
Dean
Dean's Avatar
just like on rmbs user options :D
Posted on Saturday 15th December 2007 at 05:10 PM
ShadowMage
ShadowMage's Avatar
simple, but helpful :D