DateCalAdd.java Source code

Java tutorial

Introduction

Here is the source code for DateCalAdd.java

Source

import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * DateCalAdd -- compute the difference between two dates.
 */
public class DateCalAdd {
    public static void main(String[] av) {
        /** Today's date */
        Calendar now = Calendar.getInstance();

        /* Do "DateFormat" using "simple" format. */
        SimpleDateFormat formatter = new SimpleDateFormat("E yyyy/MM/dd 'at' hh:mm:ss a zzz");
        System.out.println("It is now " + formatter.format(now.getTime()));

        now.add(Calendar.YEAR, -2);
        System.out.println("Two years ago was " + formatter.format(now.getTime()));
    }
}