Here you can find the source of getTimeOnly(final Date oDate)
public static Date getTimeOnly(final Date oDate)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static final long HOUR = 60 * 60 * 1000; public static final long MINUTE = 60 * 1000; public static final long SECOND = 1000L; public static Date getTimeOnly(final Date oDate) { if (null == oDate) { return null; }//from w w w .ja v a2s . c om final Calendar c = Calendar.getInstance(); c.setTime(oDate); c.set(Calendar.YEAR, 1970); c.set(Calendar.MONTH, 0); c.set(Calendar.DAY_OF_MONTH, 1); return c.getTime(); } public static String getTime(final long time) { if (time <= 0) { return ""; } if (time < SECOND) { return time + "ms"; } else if (time < MINUTE) { return (time / SECOND) + "s" + getTime(time % SECOND); } else if (time < HOUR) { return (time / MINUTE) + "m" + getTime(time % MINUTE); } else if (time >= HOUR) { return (time / HOUR) + "h" + getTime(time % HOUR); } return ""; } }