Answer the question
In order to leave comments, you need to log in
Can't make a script that checks the current date on the server and adds +2 days to the number in the tag?
I am learning js. I want to write a simple script that checks the current date on the server and adds +2 days to today's number, and then outputs the result to span
.
for example,
today is September 9th, the script looks at today's date, then adds +2 days and outputs the result to span
.
<p>До <span id="data">11</span> сентября получите подарок.</p>
Answer the question
In order to leave comments, you need to log in
In a loop, we check the following. array element to zero if true then continue counting
foreach | for -> if array_key_exists($key+1, $arr) and $arr[$key+1] ==0
JS in the browser has no idea what time it is on the server. You can use a server script to set the server time on the page.
var serverTimestamp = <?php echo time();?> // или какой там у вас серверный язык
var serverDate = new Date(serverTimestamp)
var day = serverDate.getDay()
document.getElementById('data').innerHTML = day + 2;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question