Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 45
0 Users 6 Guests Online

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:

Code
<script type='text/javascript'>
var date=new Date(); // Gets the full date!
var day=date.getHours(); // Gets the hours!

if(day<=11) {
document.write('Good Morning'); // If it's before 12 PM then display this!
} else if(day<18){
document.write('Good Afternoon'); // After 12 PM display this!
} else {
document.write('Good Evening'); // After 6 PM display this!
}
</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
Views:
2754
Rating:
Posted on Wednesday 7th May 2008 at 01:27 AM
DjMilez
DjMilez
Great, thanks. I'm using it now.
Posted on Saturday 29th December 2007 at 07:48 PM
Diablosblizz
Diablosblizz
But that takes more work, Shadow.
Posted on Saturday 22nd December 2007 at 09:57 PM
ShadowMage
ShadowMage
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
Good point Diablosblizz, js would be better on this than php.
Posted on Thursday 20th December 2007 at 11:42 AM
ShadowMage
ShadowMage
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
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
Yeah but here on RMB I used PHP :P

Oliver
Posted on Saturday 15th December 2007 at 09:43 PM
Diablosblizz
Diablosblizz
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
just like on rmbs user options :D
Posted on Saturday 15th December 2007 at 05:10 PM
ShadowMage
ShadowMage
simple, but helpful :D