Get time tomorrow xx: xx

What is an effective way to get a specific time the next day in Java? Let me say that I want a long time tomorrow at 03:30:00. Setting calendar fields and date formatting is obvious. Better or smarter, thanks for sharing them!

Ki

+5
source share
4 answers

I take brute force approach

// make it now
Calendar dateCal = Calendar.getInstance();
// make it tomorrow
dateCal.add(Calendar.DAY_OF_YEAR, 1);
// Now set it to the time you want
dateCal.set(Calendar.HOUR_OF_DAY, hours);
dateCal.set(Calendar.MINUTE, minutes);
dateCal.set(Calendar.SECOND, seconds);
dateCal.set(Calendar.MILLISECOND, 0);
return dateCal.getTime();
+14
source

I am curious to know what other people can say about this. My own experience is that using shortcuts (that is, “Better or Smarter Ideas”) with Datealmost always brings you trouble. Damn, just using java.util.Date, you ask for trouble.

: Joda Time .

+2

I would consider using the predefined api smart way to do this.

0
source

Not sure why you are not just using the Calendar object? It is easy and convenient. I agree that I am not using Date, pretty much everything useful in this is now deprecated. :(

0
source

All Articles