i have problem with displaying correct date. I want to display tommorow date if today is the last day in the month, and time is 20:00 PM and more.
I've tried this example, this and this but nothing worked for me.
function isLastDay(dt) {
return new Date(dt.getTime() + 86400000).getDate() === 1;
}
function changeDay() {
var d = new Date();
d.setHours(d.getHours() + (d.getTimezoneOffset() / 60) + 3);
d.setDate(31);
d.setHours(20);
var day = d.getDate();
var hrs = d.getHours();
var min = d.getMinutes();
var sec = d.getSeconds();
var dayString = 'today';
var mnt = new Array("january", "february", "march", "april", "may",
"june", "july", "august", "september", "october", "november", "december");
var lastday = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate();
if (((hrs == 19) && (min > 45)) || (hrs > 19)) {
day = day + 1;
dayString = 'tomorrow';
}
if (day === lastday) {
$(".start-web").html(day + " " + mnt[d.getMonth() + 1, 0]);
} else {
$(".start-web").html(day + " " + mnt[d.getMonth()]);
}
$(".start-web-d").html(dayString);
}
setInterval("changeDay()", 1000);
<div>
<p>
<strong>
Start
<span class="start-web-d"> </span>
<span class="start-web"> </span>
20:00
</strong>
</p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
My script shows me 32 of January, for example, and my purpose is to show 1 of February. Any help would be appreciated, thanks.
Here is the link to my example.