ASP, PHP and JavaScript code for switching CSS skins according to time periods. Everyone should know that a website can switch different CSS styles. For example, as the well-known Tencent also added the function of switching skins during its revision this year. It is a good idea to automatically adjust the site style according to time. This automatic adjustment of site style according to time is nothing new. I remember seeing similar articles or methods a long time ago, but I didn't pay special attention to it at the time. Let’s talk about their implementation methods. There are currently two implementation methods on the Internet:
1. Using
the ASP version of the server-side code:
<link rel="stylesheet" type="text/css" href="
<%
if hour(now)<12 then
response.write "morning.css"
elseif hour(now)<17 then
response.write "day.css"
else
response.write "night.css"
end if
%>
"/>
PHP version:
<link rel="stylesheet" type="text/css" href="
<?php
$hour = date("H");
if($hour < 12)
echo 'morning.css';
else if($hour < 17)
echo 'day.css';
else
echo 'night.css';
?>
" />
2. Use JavaScript code
<script type="text/javascript">
<!–
function getCSS(){
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour<12)
display = "morning.css";
else if (thehour<17)
display = "day.css";
else
display = "night.css";
//(...just add more if you want...)
var css = '<';
css+='link rel="stylesheet" href='+display+' /';
css+='>';
document.write(css);
}
–>
</script>
Considering that the client may not support or disable JavaScript, you need to set a default CSS.