Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+17 votes

Tried to use Date class to do the dates assignment. Not having a lot of success. I tried putting dates in and got different dates out (specifically the day of the year). Also tried to find an easy way to get the difference between two dates, with little success. (Saw something on Stack overflow about converting to milliseconds, but didn't have success with it personally)

Are other people having problems with this class as well?

asked in CSC490_Spring2019 by (1 point)
+2

Interesting. Can you be more specific about what went wrong? e.g. what code did you use to "put in" the date, and what wrong date "came out"?

4 Answers

+5 votes

Not sure if this will help, but you could also take a look at the GregorianCalendar class... https://developer.android.com/reference/java/util/GregorianCalendar

answered by (3.9k points)
+1

This worked for me. Much easier to use. Danke

+5 votes

I had similar problems with the date class and converting so I switched to the LocalDate class and it has methods that make adding or subtracting dates a lot easier without converting.

answered by (1 point)
+2 votes

I had better luck using a Calendar object. You still have to deal with time being in milliseconds and relative to the Unix time epoch, but I think it is the easiest object to use when dealing with dates

Calendar startTime = Calendar.getInstance();

answered by (1 point)
+1 vote

HA i don't know how to calculate leap year with date object then i switch to Calendar object, problem solved

answered by (1 point)
...