Here you can find the source of addMilliseconds(Date date, int milliseconds)
public static Date addMilliseconds(Date date, int milliseconds)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; public class Main { public static Date addMilliseconds(Date date, int milliseconds) { return add(date, Calendar.MILLISECOND, milliseconds); }/*from ww w. j av a2 s . c om*/ public static Timestamp addMilliseconds(Timestamp timestamp, int milliseconds) { return add(timestamp, Calendar.MILLISECOND, milliseconds); } private static Date add(Date date, int unit, int amount) { Calendar c = Calendar.getInstance(); c.setTime(date); 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(); } }