Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chandru
Progrm
1 Answer(s)      3 years and 3 months ago
Posted in : Java Beginners


Write a JAVA program to add or subtract days in current date and time values using JAVA calendar class.


Advertisement
View Answers

August 5, 2011 at 12:37 PM


import java.util.Calendar;

public class AddSubtractDays {

  public static void main(String[] args){
    Calendar now = Calendar.getInstance();
    System.out.println("Current date : " + (now.get(Calendar.DATE)) + "-"+ (now.get(Calendar.MONTH)+1) + "-" + now.get(Calendar.YEAR));

    now.add(Calendar.DATE, 1);

    System.out.println("date after adding days : " + (now.get(Calendar.DATE)) + "-" + (now.get(Calendar.MONTH)+1) + "-" + now.get(Calendar.YEAR));

    Calendar now1 = Calendar.getInstance();
    now1.add(Calendar.DATE, -1);

    System.out.println("date after subtracting days : " + (now1.get(Calendar.DATE)) + "-" +(now.get(Calendar.MONTH)+1) + "-" + now1.get(Calendar.YEAR));
  }
}


Related Tutorials/Questions & Answers:
Java progrm
Java progrm   Write a Java progrm that copies one text file to another, converting every lower case character to upper case equivalent. Names of surces file and destination file should be passed from command line.   
Advertisements
upload a file into database and progrm should support excel and text and csv file formats
upload a file into database and progrm should support excel and text and csv file formats  Hai all, I need a program to upload a file into database table... and the program should support .excel ,.txt ,.csv file formats. can
thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
Regarding path settings in java
Regarding path settings in java  Hello I had a problem of setting paths in Java.I setted classpath(C:\java\j2sdk1.4.2\lib) and path(c:\java\j2sdk1.4.2\bin) in system variables. But when i compile simple java progrm
Java
Java  I compiling my jdbcodbc progrm. D:\Java\jdk1.6.0\bin>javac JdbcExample.java JdbcExample.java:12: cannot find symbol symbol : method ClassforName(java.lang.String) location: class JDBCExample ClassforName
code error - JSP-Servlet
is error in this progrm. ss function describe() { window.status
jdbc
jdbc  I compiling my jdbcodbc progrm. D:\Java\jdk1.6.0\bin>javac JdbcExample.java JdbcExample.java:12: cannot find symbol symbol : method ClassforName(java.lang.String) location: class JDBCExample ClassforName
Advertisements
 

 

 

DMCA.com