I wrote the following code in JS
var d = new Date(2019, 9, 14);
var currentTime = d.getTime();
var daysToAdd = 3;
var secondsInDay = 86400;
var d = new Date(currentTime + daysToAdd*secondsInDay);
var year = d.getFullYear();
var month = ("0" + (d.getMonth())).slice(-2);
var day = ("0" + d.getDate()).slice(-2);
console.log('result in Y-M-D is: ' + year + '-' + month + '-' + day);
This happens because on this code
new Date(currentTime + daysToAdd*secondsInDay);
secondsInDay is a representation in seconds, and currentTime is represented in ms. If you multiply your secondsInDay by 1000 (to get the equivalent value in ms) you will get the desired date.
Instead of
var d = new Date(currentTime + daysToAdd*secondsInDay);
you can use
d.setDate(new Date().getDate()+3);
Youre problem is that the constructor of the date object uses MILISECONDS to calculate the date, and you're using SECONDS to add that 3 extra days. Instead of 86400 (seconds) you need to use the value 86400000 (miliseconds).
Goodbye!
I am building a web portal with solidity contract integration. In the contract, I have saved the date in uint from like this 1539491531. When I show it on the web page it looks like this: It showing ...
I am building a web portal with solidity contract integration. In the contract, I have saved the date in uint from like this 1539491531. When I show it on the web page it looks like this: It showing ...
I'm struggling with ui-router configuration which will define basic CRUD in the application. I need to be able to add, remove, edit and search for, say, clients. Quite basic task. Main page with ...
I'm struggling with ui-router configuration which will define basic CRUD in the application. I need to be able to add, remove, edit and search for, say, clients. Quite basic task. Main page with ...
I am a student and very new to JS, like this is my first project dealing with it. With that being said, please excuse how juvenile my coding may seem to you experts. I followed the instructions of my ...
I am a student and very new to JS, like this is my first project dealing with it. With that being said, please excuse how juvenile my coding may seem to you experts. I followed the instructions of my ...
I'm trying to iterate over a simple array using recursion. For this specific case, I'm trying to recreate .map() using recursion (without using .map()!. I currently am only pushing the last element ...
I'm trying to iterate over a simple array using recursion. For this specific case, I'm trying to recreate .map() using recursion (without using .map()!. I currently am only pushing the last element ...