Skip to content Skip to sidebar Skip to footer

Dynamic Javascript Date Pointing Date For Tomorrow

I am using the below script to create dynamic date. The HTML: The Script: var months = ['01','02','03','04','05','06','07', '08','0

Solution 1:

Because you add a day when you initialize your date?

 //You add 1000*3600*24 milliseconds: 1 day ===> outcome is tomorrow
 tomorrow.setTime(tomorrow.getTime() + (1000*3600*24)); 

Try

var tomorrow = newDate(Date.now());

Fiddle: http://jsfiddle.net/n4e87x6k/3/

Maybe it's also usefull to change your parameter from "tomorrow" to "today" ;-)

Solution 2:

This is because you add a whole day to the current time on the Date constructor. If you want to display the current Date use

var today = newDate();

and replace

document.getElementById("spanDate").innerHTML = ('00' + tomorrow.getDate()).slice(-2) + "/" + months[tomorrow.getMonth()] + "/" + tomorrow.getFullYear();

with

document.getElementById("spanDate").innerHTML = ('00' + today.getDate()).slice(-2) + "/" + months[today.getMonth()] + "/" + today.getFullYear();

Post a Comment for "Dynamic Javascript Date Pointing Date For Tomorrow"