How can I retrieve the ISO time three days from now using javascript?

Is there a way to retrieve the date in ISO format three days from now?

I know how to get today's date using this code snippet, but I'm uncertain about how to calculate the ISO date for three days in the future.

const today = new Date().toISOString().substring(0, 10);

Answer №1

This custom script allows you to effortlessly adjust hours, minutes, and seconds as needed.

function customizeTime(date, addTime){
  let newTime=date.getTime();
  if(addTime.seconds) newTime+=1000*addTime.seconds; //check for extra seconds 
  if(addTime.minutes) newTime+=1000*60*addTime.minutes;//check for extra minutes 
  if(addTime.hours) newTime+=1000*60*60*addTime.hours;//check for extra hours 
  return new Date(newTime);
}

Date.prototype.customizeTime = function(addTime){
  return customizeTime(new Date(), addTime); 
}

let updatedDate = new Date().customizeTime({
    hours: 24 * 3, //Adding 3 days
    seconds: 0 //No additional seconds included
}).toISOString().substring(0, 10);

console.log( updatedDate );

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the deal with JavaScript's Global Array?

Currently, I am exploring how to utilize a Global Array with 500 elements and incorporating an image in jpg format that is sized at 20x20. The main objective is to have the image replicated on the screen multiple times. Here is my current progression: ( ...

Sending a response in the catch block based on conditions

I am currently working on finding the correct method to handle a potential bad Fetch response. My goal is to immediately send a 500 response and halt the code execution if the Fetch response is not okay. However, if the response is acceptable, I need to ...

Is there a way to protect the privacy of State variables within a Flux Store?

Currently, I've implemented my own version of the Flux pattern in a small scale in order to deepen my understanding of the concept. So far, it's been working well and I've been gaining valuable insights! However, I've encountered a chal ...

Feeling lost on how to utilize .map, .reduce, or foreach in my code

Recently delving into JavaScript, I find myself a bit perplexed despite scouring through various answers and resources on Mozilla.org. My struggle lies in seamlessly using .map and .filter on straightforward arrays, but feeling a bit lost when it comes to ...

Get the file from the web browser

Hey there, greetings from my part of the world. I have some straightforward questions that I'm not sure have simple answers. Currently, I am working on a web application using the JSP/Servlet framework. In this app, users can download a flat text fil ...

JavaScript bundling encountered an unexpected token for 'else', causing an exception

After successfully running my JavaScript files individually, I encountered an issue when bundling them using the SquishIt Framework. An error regarding an unexpected token 'else' appeared in a new file where all the files were combined. To addre ...

Error occurs in React Native when trying to import routes due to type mismatch

My react native app is running on my physical device, but I encountered an error when importing routesContainer in my app.js. Can anyone shed some light on why this error is occurring? TypeError: Super expression must either be null or a function [Mon Oct ...

Utilizing the "return" keyword in Javascript outside of function declarations

Exploring the Impact of Using the Return Keyword in JavaScript Scripts Beyond Functions in Browsers and Node.js Recently, I experimented with utilizing the return keyword in a Node.js script like so: #!/usr/bin/env node return 10; My initial assumption ...

Instructions on uploading a PDF file from a Wordpress page and ensuring the file is stored in the wp-content upload directory folder

What is the process for uploading a PDF file on a WordPress page? <form action="" method="POST"> <input type="file" name="file-upload" id="file-upload" /> <?php $attachment_id = media_handle_upload('file-upload', $post->I ...

Navigating to the default landing page using basic authentication middleware in Express

I'm currently working on implementing basic authorization for an entire website using Express. The goal is to have users enter their credentials, and if correct, they will be directed to the standard landing page. If the credentials are incorrect, the ...

The userName data is not being displayed in the console.log when using socket.io

I'm currently in the process of developing a chat application using socket.io. My goal is to log the user's name when they join the chat. I have set up a prompt on the client side to capture the user's input and emit it to the server. Howeve ...

What is the proper way to use special characters like "<>" in a parameter when sending a request to the server using $.ajax?

Upon submission from the client side, a form is sent to the server using $.ajax: function showSearchResults(searchText, fromSuggestions) { $.ajax({ url: "/Home/Search", data: { searchText: searchText, fromSuggestions: fromSuggestions } ...

Angular's $q.defer() function will yield an object with a "then" function

In my Angular file, I am attempting to access a database using $http and then store the retrieved data in a $scope variable for display on the webpage. However, I am encountering difficulties with $q.defer not running as expected. When I check the consol ...

Utilize JQuery's .append() method to insert a new element into the DOM and then trigger an "on click" event within

I am attempting to use the .append() method to add a new radio button, and then when I click on the new radio buttons, trigger a new function. However, I am having trouble achieving this with my current code: HTML: <label>Where should the photo be ...

Display array elements in a PDF document using pdfmake

Upon reaching the final page of my Angular project, I have an array filled with data retrieved from a database. How can I utilize pdfmake to import this data into a PDF file? My goal is to display a table where the first column shows interv.code and the ...

Capture the occurrence of a form not being submitted to the server because of validation issues

I have a simple ASP.NET MVC form that includes validation. The validation is set up with attributes/data annotations in the viewmodel, and I have both client-side and server-side validation enabled on my website - a common setup. When the form is submitte ...

Just started working with React and encountered this initial error message in my project

Welcome to Windows PowerShell! Upgrade to the latest version of PowerShell to enjoy new features and enhancements! PS D:\React> cd textutils PS D:\React\textutils> npm start npm WARN config global `--global`, `--local` are deprecated ...

Enhancing performance by dynamically updating DOM elements when they come into view during scrolling

Currently, I am in search of an efficient algorithm to dynamically load background-images for a group of <li>'s but I am encountering some efficiency issues. The code I am using at the moment is as follows: function elementInView($elem, vps, vp ...

Increment the counter value by one when a new class is created or appended

My goal is to develop a system that increments the 'fault' counter by one every time a wrong answer is submitted. To achieve this, I have configured my system to detect when a class named "incorrectResponse" is generated. However, I am encounteri ...

Triggering download of .CSV file in Angular 2 upon user click with authentication

Using a Spring Boot backend, my API utilizes a service to send data through an OutputStreamWriter. In Angular 2, I can trigger a download by clicking on a button: In Typescript results(){ window.location.href='myapicall'; } In HTML <bu ...