JavaScript Why am I getting this error for JavaScript Date object? getting error this site can’t be reached,getting error

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);
Answer:1

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.

Answer:2

Instead of

var d = new Date(currentTime + daysToAdd*secondsInDay);

you can use

d.setDate(new Date().getDate()+3);
Answer: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!

Answer:4

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 ...

  1. two dimensional array iteration in java
  2. 2 dimensional array iteration
  3. two dimensional array iteration
  4. javascript two dimensional array iteration
  5. c# two dimensional array iteration
  6. php multidimensional array iteration