Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get next day java.sql.Date

Tags:

java

date

I have a Date object (java.sql.Date). I need to get 12 at night of that day. So I can create a time period from current time to end of the day.

How can I calculate that time with java.sql.Date. Please send me an example.

like image 457
tiran Avatar asked Nov 28 '22 03:11

tiran


1 Answers

Using java.util.Calendar

java.sql.Date sqlDate = ...;
Calendar cal = Calendar.getInstance();
cal.setTime(sqlDate);
cal.add(Calendar.DAY_OF_YEAR,1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
java.sql.Date sqlTommorow = new java.sql.Date(cal.getTimeInMillis());
like image 172
Jarek Przygódzki Avatar answered Dec 09 '22 19:12

Jarek Przygódzki