0

When the user opens my app the date is recorded. Then it's compared with the last date that was recorded. I want to be able to tell if just the day changed between the 2. And I don't want to simply see if 24 hours lapsed. The user should be able to open the app at 11:59pm, and then again in 2 minutes and the code should tell that the day has changed. Thanks for your help!

Ben Mora
  • 279
  • 3
  • 16

2 Answers2

0

I found a solution that solves my problem (although technically doesn't directly get the day out of the Day object.)

Comparing two java.util.Dates to see if they are in the same day

Basically make a Calendar object and call it's "setTime()" method with my Date object as the argument, then use ".get(Calendar.DAY_OF_YEAR) to get the day from each Calendar object.

Ben Mora
  • 279
  • 3
  • 16
0

You are right, and if you want to get the actual day you just need to use Calendar.getInstance() like this:

Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_MONTH); 
Nico Halpe
  • 398
  • 2
  • 9