Answers for "how to add one day to a date in java"

2

add days to date java

LocalDate date=LocalDate.now();
date.addDays(1);
System.out.println(date);
Posted by: Guest on April-16-2021
0

add one day to current timestamp date in java

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
 
public class AddTime {
  public static void main( String[] args ) {
 
    Timestamp timestamp = new Timestamp(new Date().getTime());
    System.out.println(timestamp);
 
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(timestamp.getTime());
 
    // add 30 seconds
    cal.add(Calendar.SECOND, 30);
    timestamp = new Timestamp(cal.getTime().getTime());
    System.out.println(timestamp);
 
    // add 5 hours
    cal.setTimeInMillis(timestamp.getTime());
    cal.add(Calendar.HOUR, 5);
    timestamp = new Timestamp(cal.getTime().getTime());
    System.out.println(timestamp);
 
    // add 30 days
    cal.setTimeInMillis(timestamp.getTime());
    cal.add(Calendar.DAY_OF_MONTH, 30);
    timestamp = new Timestamp(cal.getTime().getTime());
    System.out.println(timestamp);
 
    // add 6 months
    cal.setTimeInMillis(timestamp.getTime());
    cal.add(Calendar.MONTH, 6);
    timestamp = new Timestamp(cal.getTime().getTime());
    System.out.println(timestamp);
  }
}
 
 
Posted by: Guest on March-17-2021
0

calendar java add 1 day

Calendar c = Calendar.getInstance(TimeZone.getDefault());
c.add( Calendar.DATE, 1 );
Posted by: Guest on January-27-2021

Code answers related to "how to add one day to a date in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language