Answer the question
In order to leave comments, you need to log in
How to make automatic date change js?
The task is to make an automatic date change. The date should change every 15 days, for example, from 1-15 there is one date, from 15-30 another, but it doesn’t work out. Here's a little bit of code:
<!-- clock hack -->
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Пример</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
var dt = new Date();
// Display the month, day, and year. getMonth() returns a 0-based number.
var day = dt.getDate()+5;
var month = dt.getMonth()+1;
var year = dt.getFullYear();
document.write(day + '-' + month + '-' + year);
// Output: current month, day, year
</script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
var dt = new Date();
var date = dt.getDate();
if( date < 15) dt.setDate(1); // до 15-го числа будет 1-е
else dt.setDate(15); // после 15-го – 15-е
// Display the month, day, and year. getMonth() returns a 0-based number.
var day = dt.getDate();
var month = dt.getMonth()+1;
var year = dt.getFullYear();
document.write(day + '-' + month + '-' + year);
On the page for example:
<div> Current Time
<span id="clock"></span>
</div>
window.onload = function(){
function showClock(){
var time = new Date();
var hour = time.getHours();
var minute = time.getMinutes();
var sec = time.getSeconds();
var timeFormatter = digitFormatter(hour)+':'+digitFormatter(minute)+':'+digitFormatter(sec);
var clock = document.getElementById("clock");
clock.textContent = timeFormatter;
}
function digitFormatter(num){
if(num<10){
return '0'+num;
}else{
return num;
}
}
showClock();
setInterval(showClock,1000)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question