Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+11 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 (8 points)
+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

+4 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 (13 points)
+1

This worked for me. Much easier to use. Danke

+4 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 (8 points)
+1 vote

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 (8 points)
0 votes

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

answered by (8 points)
...