Search code examples
androidandroid-date

How to add time to another time - Android


I have timer for a task. And all the sessions will be added up to each other.

Let's say today user spent 5 minutes

Other day he spent 1 hour, here this one hour will be added to the 5 minutes

and so on..

So it will be the total time in one value..

How can I do this ? Is it by Milliseconds or Date object ?


Solution

  • Date is more useful when you are dealing with actual calendar dates.

    If you just want to keep track of time intervals/durations, just have a long variable and keep on adding the durations to this.

    EDIT : Long.MAX_VALUE is 9,223,372,036,854,775,807. So, you don't really need to worry about the overflow either.