Write a JAVA program to add or subtract days in current date and time values using JAVA calendar class.
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
java with xmljava 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 xmljava 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 javaRegarding 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 jdbcjdbc 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
JavaJava 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