menambahkan menit pada object tanggal sekarang

Bagaimana menambahkan beberapa menit setelah waktu sekarang (current time) pada Java ?
Misalnya saya ingin menambahkan 20 menit dari waktu sekarang,,

public class Tanggal {
  
  public static void main(String[] args) {
    System.out.println("Tes tanggal ");
    
    Calendar cal =  Calendar.getInstance();
    System.out.println("Waktu " + cal.get(Calendar.HOUR_OF_DAY) +
        ":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
    
    Date tgl = new Date();
    System.out.println("Tanggal = "+tgl);
    tgl = cal.getTime();
    System.out.println("Tanggal 2 = "+tgl);
    
    cal.add(Calendar.MINUTE, 20);
    
    System.out.println("Waktu plus 20 menit " + cal.get(Calendar.HOUR_OF_DAY) +
        ":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
    
    
    
  }

}

== Hasil ===

run:
Tes tanggal
Waktu 10:57:9
Tanggal = Tue Jan 24 10:57:09 CIT 2012
Tanggal 2 = Tue Jan 24 10:57:09 CIT 2012
Waktu plus 20 menit 11:17:9
BUILD SUCCESSFUL (total time: 0 seconds)

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s