Convert java.util.Date to java.sql.Time after calculation
import java.util.GregorianCalendar;
public class Main {
/**
* Add the java.util.Time forward or backward.
* @param startDate - The start date
* @period Calendar.YEAR etc
* @param amount - Negative to roll backwards.
*/
public static java.sql.Time rollTime( java.util.Date startDate, int period, int amount )
{
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(startDate);
gc.add(period, amount);
return new java.sql.Time(gc.getTime().getTime());
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Date Convert:
- Convert Calendar to java.sql.Date
- Convert day of year to day of month
- Convert java.util.Date to java.sql.Time after calculation
- Convert java.util.Date to java.sql.Date after calculation
- Convert java.util.Date to java.sql.Date
- Convert Date into milliseconds
- Convert date to GMT
- Convert day of the year to date
- Convert milliseconds to readable string
- Elapsed time in hours/minutes/seconds
- Convert longs (time_t in UNIX terminology) to seconds