Hi, i am new to this forum after seeing different valuable replies i am posting my query..
Need a HTML script that can define the background color a text with respect to time.. for ex. i have some five texts say 1hr,2hr,3hr,4hr,5hr.

Now my script should check the local time and then decide the background color of the text.

is there any solution for this, please let me know.

Javascript is probably the best method for this. But you could also do it in any server side implementation as well.
javascript date and time

Javascript is probably the best method for this. But you could also do it in any server side implementation as well.
javascript date and time

Is there any sample that you can provide me u with both options javascript and server side implementation

Javascript is probably the best method for this. But you could also do it in any server side implementation as well.
javascript date and time

suppose you have ids of text elements as you mention:
"1hr, 2hr, 3hr, 4hr, 5hr...."

javascript: var  D = new Date(); var h = D.getHours();
document.getElementById(h+'hr').style.backgroundColor = "red"

that would set the correct text element background color to a (highly) distinctive color there. :')
If you'd like it current without refreshing the page you should use a timer check...

Is there any sample that you can provide me u with both options javascript and server side implementation

I would do something like:

var currentTime = new Date()
var hours= currentTime.getHours() 
if(hours < 11){
document.getElementById('greetingID').style.color = '#ff0000';
}

This would make the text color red, if it was before 11am. You could expand on that if statement to better match what you need, but you get the idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.