1import java.sql.Timestamp;
2import java.util.Calendar;
3import java.util.Date;
4
5public class AddTime {
6 public static void main( String[] args ) {
7
8 Timestamp timestamp = new Timestamp(new Date().getTime());
9 System.out.println(timestamp);
10
11 Calendar cal = Calendar.getInstance();
12 cal.setTimeInMillis(timestamp.getTime());
13
14 // add 30 seconds
15 cal.add(Calendar.SECOND, 30);
16 timestamp = new Timestamp(cal.getTime().getTime());
17 System.out.println(timestamp);
18
19 // add 5 hours
20 cal.setTimeInMillis(timestamp.getTime());
21 cal.add(Calendar.HOUR, 5);
22 timestamp = new Timestamp(cal.getTime().getTime());
23 System.out.println(timestamp);
24
25 // add 30 days
26 cal.setTimeInMillis(timestamp.getTime());
27 cal.add(Calendar.DAY_OF_MONTH, 30);
28 timestamp = new Timestamp(cal.getTime().getTime());
29 System.out.println(timestamp);
30
31 // add 6 months
32 cal.setTimeInMillis(timestamp.getTime());
33 cal.add(Calendar.MONTH, 6);
34 timestamp = new Timestamp(cal.getTime().getTime());
35 System.out.println(timestamp);
36 }
37}
38
39