How to add one day to a date?
Given a Date dt
you have several possibilities:
Solution 1: You can use the Calendar
class for that:
Date dt = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.DATE, 1);
dt = c.getTime();
Solution 2: You should seriously consider using the Joda-Time library, because of the various shortcomings of the Date
class. With Joda-Time you can do the following:
Date dt = new Date();
DateTime dtOrg = new DateTime(dt);
DateTime dtPlusOne = dtOrg.plusDays(1);
Solution 3: With Java 8 you can also use the new JSR 310 API (which is inspired by Joda-Time):
Date dt = new Date();
LocalDateTime.from(dt.toInstant()).plusDays(1);
Adding one day to a date
<?php
$stop_date = '2009-09-30 20:24:00';
echo 'date before day adding: ' . $stop_date;
$stop_date = date('Y-m-d H:i:s', strtotime($stop_date . ' +1 day'));
echo 'date after adding 1 day: ' . $stop_date;
?>
For PHP 5.2.0+, you may also do as follows:
$stop_date = new DateTime('2009-09-30 20:24:00');
echo 'date before day adding: ' . $stop_date->format('Y-m-d H:i:s');
$stop_date->modify('+1 day');
echo 'date after adding 1 day: ' . $stop_date->format('Y-m-d H:i:s');
How can I add 1 day to current date?
To add one day to a date object:
var date = new Date();
// add a day
date.setDate(date.getDate() + 1);
Add one day to date in javascript
Note that Date.getDate
only returns the day of the month. You can add a day by calling Date.setDate
and appending 1.
// Create new Date instance
var date = new Date()
// Add a day
date.setDate(date.getDate() + 1)
JavaScript will automatically update the month and year for you.
EDIT:
Here's a link to a page where you can find all the cool stuff about the built-in Date object, and see what's possible: Date.
add day to date javascript
Try this
var date1 = new Date("03/31/2016");var next_date = new Date(date1.getTime() + 86400000);alert(next_date.toLocaleDateString());
Google App Script Adding one Day to a date
Change it to:
var testDate = new Date();
var secondDate = new Date();
secondDate.setDate(testDate.getDate()+1);
This should keep the day good for daylight savings time changes and leap year as well.
Related Topics
How to Extract Text from Word File .Doc,Docx,.Xlsx,.Pptx PHP
How Can Strip Whitespaces in PHP'S Variable
How to Add a PHP Page to Wordpress
How to Create a Copy of an Object in PHP
Simple PHP Strpos Function Not Working, Why
Listing All the Folders Subfolders and Files in a Directory Using PHP
How to Properly Indent PHP/Html Mixed Code
Is MySQL_Real_Escape_String() Broken
How to Insert Element into Arrays At Specific Position
How to Upload & Save Files With Desired Name
Dompdf and Set Different Font-family
Writing a New Line to File in PHP (Line Feed)
Best Way to Test For a Variable'S Existence in PHP; Isset() Is Clearly Broken
In a PHP/Apache/Linux Context, Why Exactly Is Chmod 777 Dangerous
Are MySQL_Real_Escape_String() and MySQL_Escape_String() Sufficient For App Security