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 might as 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 thing here, but it’s unnecessary complication and waste of resources:
$horaatual = DateTime::createFromFormat('H:i a', $current_time);
Notice three important things:
- If the least minute is needed, adjust the
time()
for ( time() + 1 )
and take it out on the rest;
- If you want local time, adjust the
time()
with the desired spindle, in seconds, and/or adjust the server timezone correctly to the test region;
- There are many other ways to do it, the important thing is logic. It has diverse functions of date and time in the manual.
I’m sorry, but I don’t understand where to edit $horainicio, I replace or create a new string ?
– Matheus Vitor
Do not forget to set the server time to the correct time zone of the desired time.
– Bacco
I used $horaatual = date('H:i:s' );
– Matheus Vitor
check the server side time and add
display
in div when you want to display or not– Ricardo Pontual