JSFiddle - React, Tailwind, and code Playground

by Vitaliy

HTML

<div id="time"></div>

JavaScript

var d  = new Date();
var cur_month = +d.getMonth() + 1, cur_day = d.getDate(), cur_year = d.getFullYear();
if(d.getDate() < 15){
	next_date_string = cur_month + "." + "15" + "." + cur_year;
	var new_date = new Date(next_date_string);
	var time = parseInt((new_date.getTime() - d.getTime())/1000);
	//alert("days: " + left.days + "hours: " + left.hours +  "minutes: " + left.minutes);	
	var interval = setInterval(function(){
		time -= 1;
		left = timeLeft(time);
		document.getElementById("time").innerHTML = "осталось: " + left.days + "дней; " + left.hours + "часов; " + left.minutes + "минут; " + left.seconds + "секунд;";
		if(time <= 1){
			clearInterval(interval);
		}
	}, 1000);
}
else{
	if(cur_month < 12){
		++cur_month;
	}	
	else{
		cur_month = 1;
		++cur_year;
	}
	next_date_string = cur_month + "." + "15" + "." + cur_year;
	var new_date = new Date(next_date_string);
	var time = parseInt((new_date.getTime() - d.getTime())/1000);
	var interval = setInterval(function(){
		time -= 1;
		left = timeLeft(time);
		document.getElementById("time").innerHTML = "осталось: " + left.days + "дней; " + left.hours + "часов; " + left.minutes + "минут; " + left.seconds + "секунд;";
		if(time <= 1){
			clearInterval(interval);
		}
	}, 1000);
}
function timeLeft(time){
	var left = {};
	left.days = parseInt(time/(24*60*60));
	left.hours = parseInt((time - left.days*(24*60*60))/3600);
	left.minutes = parseInt((time - left.days*(24*60*60) - left.hours*(60*60))/60);
	left.seconds = parseInt(time - left.days*(24*60*60) - left.hours*(60*60) - left.minutes*60);
	return left;
}