Javascript: when it is midnight add +1 on the date

-1

My date when midnight arrives continues the day before, I wanted it to go to the next day.

For example:

At 23:50 on the 6th, it shows Saturday, October 6, 2018 at 00:00

As the midnight is already the next day, I want it to stay: Sunday, October 7, 2018, at 00:00

PS: I do not know how to program c (:

<html>
    <head>
        <script language="javascript" type="text/javascript">
            var d = new Date();
            now = new Date;
            monName = new Array ("Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
            dayName = new Array ("Domingo","Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado");
            hourName = new Array (00,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,"00");
        </script>
    </head>
    <body>
        <script language="javascript" type="text/javascript">
            document.write ("<center><span style='width: 50%; font-size: 18px; line-height: 24px; color: #000000;'>" + dayName [now.getDay()] + ", " + now.getDate() + " de " + monName [now.getMonth()] + " de " + now.getFullYear() + ", às " + hourName [now.getHours()+1] + ":00" + " </span></center>")
        </script>
    </head>
</html>
    
asked by anonymous 06.10.2018 / 08:21

1 answer

0

Dude, I highly recommend you look at and dig deeper into:

JavaScript Timing Events

You can take a look at this link: link

Here below I'll be putting a code (reverse to what you want) that counts down

// Set the date we're counting down to / Seta a data inicial para contagem regressiva
var countDownDate = new Date("Oct 6, 2018 23:59:59").getTime();

// Update the count down every 1 second / atualiza o contador a cada 1s
var x = setInterval(function() {

    // Get todays date and time / pega a data e hora de agora
    var now = new Date().getTime();
    
    // Find the distance between now and the count down date / acha a distancia da data atual e do contador 
    var distance = countDownDate - now;
    
    // Time calculations for days, hours, minutes and seconds / calcula o dia horas minutos e segundos que faltam
    var days = Math.floor(distance / (1000 * 60 * 60 * 24));
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    
    // Output the result in an element with id="demo" / mostra na tela dentro do elemento com id = "demo"
    document.getElementById("demo").innerHTML = days + "d " + hours + "h "
    + minutes + "m " + seconds + "s ";
    
    // If the count down is over, write some text / quando o contador chegar em 0 apresenta "expirado"
    if (distance < 0) {
        clearInterval(x);
        document.getElementById("demo").innerHTML = "EXPIRED";
    }
}, 1000);
p {
  text-align: center;
  font-size: 60px;
  margin-top: 0px;
}
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<p id="demo"></p>
</body>
</html>
    
06.10.2018 / 19:11