Basically this:
<?php
$horaatual = time() % 86400;
$horade = 18 * 60 * 60;
$horaate = 24 * 60 * 60 - 1; // Tirei um pra ficar 23:59:59
if ($horaatual >= $horade and $horaatual <= $horaate) {
?>
<div class="conteudo">
<h1>aqui vai o conteudo da div</h1>
</div>
<?php } ?>
Or they could very well be strings:
<?php
$horaatual = date('H:i:s' ); // use gmdate() para UTC
$horade = '18:00:00';
$horaate = '23:59:59';
if ($horaatual >= $horade and $horaatual <= $horaate) {
?>
<div class="conteudo">
<h1>aqui vai o conteudo da div</h1>
</div>
<?php } ?>
Some people do this crazy here, but it's unnecessary complication and waste of resources:
$horaatual = DateTime::createFromFormat('H:i a', $current_time);
Note three important things:
- If the minute is needed, set the
time()
to ( time() + 1 )
and discard the rest;
- If you want local time, set the
time()
to the desired time zone in seconds, and / or set the server timezone correctly to the test region;
- There are many other ways to do it, the important thing is logic. It has different date and time functions in the manual.