Если сайт является spa то будет необходимо реализовать постоянную проверку времени и изменение темы путем вызова метода changeTheme.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link id="time-theme" rel="stylesheet" href="">
<script src="./time-theme.js"></script>
</head>
<body>
</body>
</html>
let timeRanges = new Set([
{range: {from: `24`, to: `4`}, name:`night`, href:`./dark-theme.css`},
{range: {from: `4`, to: `12`}, name: `morning`, href:`./light-theme.css`},
{range: {from: `12`, to: `17`}, name: `day`, href:`./light-theme.css`},
{range: {from: `17`, to: `24`}, name: `evening`, href:`./dark-theme.css`},
]);
const changeTheme = timeRanges => {
let currentHour = new Date().getHours();
for(let {range, href, name} of timeRanges){
if(currentHour >= range.from && currentHour <= range.to){
Object.assign(document.querySelector(`link#time-theme`), { href });
break;
}
}
}
changeTheme(timeRanges);