Jump to content

[SOLVED] timezone based greeting


gwolff2005

Recommended Posts

Hi guys,

 

I have this code here for a time based greeting but it just shows Good evening. Does anyone know whats wrong?

Thanks in advance!!

 

 <script type="text/javascript">
/*<![CDATA[*/
	function clock()
	{
		//////////////////////////////////////////////////////
		//Coded by the notorious jackpf
		/////////////////////////////////////////////////////

		//generate time
		var time = new Date();
		var hours = time.getHours();
		var minutes = time.getMinutes();
		var seconds = time.getSeconds();

		//add preceding 0s, if required
		var hours = (hours < 10 ? '0' : '')+hours;
		var minutes = (minutes < 10 ? '0' : '')+minutes;
		var seconds = (seconds < 10 ? '0' : '')+seconds;

		//generate formated time
		var time = hours+':'+minutes+':'+seconds;

		//get where abouts in the day it is
		if(hours >= 0 && hours < 12)
		{
			var greeting = 'Good Morning';
		}
		if(hours >= 13 && hours < 18)
		{
			var greeting = 'Good Afternoon';
		}
		else
		{
			var greeting = 'Good Evening';
		}

		//display time
		document.getElementById('clock').innerHTML = time+'<br />'+greeting;
	}
	//init clock
	window.onload = function()
	{
		clock();
		setInterval('clock()', 1000);
	}
/*]]>*/
</script>

Link to comment
https://forums.phpfreaks.com/topic/153975-solved-timezone-based-greeting/
Share on other sites

this is a PHP help forum lol :P

 

The code looks fine to me. Maybe you should wait till it is morning or afternoon? then check ;)

More then likely your webhost timezone is different to your own. It may be morning or afternoon for you, but possibly evening where the server is located. Which is why it would say evening now.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.