Here you can find the source of add(Date date, int unit, int amount)
private static Date add(Date date, int unit, int amount)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; public class Main { private static Date add(Date date, int unit, int amount) { Calendar c = Calendar.getInstance(); c.setTime(date);/* w w w .j a va2s .c o m*/ c.add(unit, amount); return c.getTime(); } private static Timestamp add(Timestamp timestamp, int unit, int amount) { Calendar c = Calendar.getInstance(); c.setTime(timestamp); c.add(unit, amount); Timestamp ts = new Timestamp(c.getTimeInMillis()); ts.setNanos(ts.getNanos() + timestamp.getNanos() % 1000000); return ts; } public static int getNanos(Timestamp timestamp) { return timestamp.getNanos(); } }