Create a DateTime class that contains month, day, year, hour, minute, second.
Don't forget useful constructors and observers.
Plus also make sure to have toString for your date.
Add useful date functions:
Add seconds - take int and create a new date
adding the specified number of seconds.
Add days - take int and create a new date
adding the correct number of days.
Diff seconds - take another date and return
the difference in seconds (int).
Diff days - take another date and return
the difference in days (double).
DateTime d1 = new DateTime(10,31,2018,15,28,10);
S.o.p("Today is " + d1);//-> 10/31/2018 15:28:10
DateTime d2 = d1.addDays(7);
S.o.p("Next week is " + d2);//-> 11/7/2018 15:28:10
DateTime d3 = d1.addDays(60);
S.o.p("Two months is " + d3);//-> 12/30/2018 15:28:10
DateTime d4 = new DateTime(11,5,2018,3,28,10);
S.o.p("Another day is " + d4);//-> 11/5/2018 3:28:10
double diff = d1.diffDays(d4);
S.o.p("Time between " + d1 + " and " + d4 +
" is " + diff); //-> 4.5
This assignment has been answered 4 times in private sessions.
© 2023 Codify Tutor. All rights reserved