DateAddHour.java Source code

Java tutorial

Introduction

Here is the source code for DateAddHour.java

Source

import java.util.Calendar;

public class DateAddHour {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        System.out.println("Original = " + calendar.getTime());

        // Subtract 2 hour from the current time
        calendar.add(Calendar.HOUR, -2);

        // Add 30 minutes to the calendar time
        calendar.add(Calendar.MINUTE, 30);

        // Add 300 seconds to the calendar time
        calendar.add(Calendar.SECOND, 300);
        System.out.println("Updated  = " + calendar.getTime());
    }
}