How to do it?
I need two CSS files:
day.css - styles for the daytime.
/* Day. */
body
{
color: black;
background-color: yellow;
}
night.css - styles for the nighttime.
/* Night. */
body
{
color: white;
background-color: black;
}
and small PHP code, to recognize the current hour to check the time.
<?php
//Step #1 - Set teh timezone
date_default_timezone_set ("America/Denver");
//Step #2 - Get current hour (in 24 hours system).
$currentHour=date('H',time());
//Step #3 - Check the daytime.
if ($currentHour > 21 AND $currentHour < 7)
{
//Night.
echo 'night';
}
else
{
//Day.
echo 'day';
}
?>
Now, I integrate the PHP code with my HTML code in the index.php file.
<html>
<head>
<link REL="Stylesheet" HREF="<?php
//Step #1 - Set teh timezone
date_default_timezone_set ("America/Denver");
//Step #2 - Get current hour (in 24 hours system).
$currentHour=date('H',time());
//Step #3 - Check the daytime.
if ($currentHour > 21 AND $currentHour < 7)
{
//Night.
echo 'night';
}
else
{
//Day.
echo 'day';
}
?>.css" TYPE="text/css">
</head>
<body>
<h1>
The colours of the text and background are depended of the time:<br>
- night style from 10 PM to 06 AM;<br>
- day style from 06 AM to 10 PM.
</h1>
</body>
</html>
Finally visitors can enjoy my Web Page (they can be surprise when they visit my page).













