代码示例:(标识:eg_js_ifthen)
<!DOCTYPE html>
<html>
<body>

<p>如果小时小于18:00,显示“美好的一天!”:</p>

<p id="demo">晚安</p>

<script>
if (new Date().getHours() < 18) {
  document.getElementById("demo").innerHTML = "美好的一天!";
}
</script>

</body>
</html>
运行结果: