Add another 12 hours and print out the date and time in Java

Description

The following code shows how to add another 12 hours and print out the date and time.

Example


//from   w w  w.ja  va  2s  .  c o  m
import java.text.DateFormat;
import java.util.Calendar;

public class Main {
  public static void main(String s[]) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL,
        DateFormat.MEDIUM);

    System.out.println(df.format(cal.getTime()));

    cal.add(Calendar.AM_PM, 1);
    System.out.println(df.format(cal.getTime()));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Date »




Date Get
Date Set
Date Format
Date Compare
Date Convert
Date Calculation
Date Parse
Timezone