Do we have a TimeSpan sort of class in Java

前端 未结 4 1156
名媛妹妹
名媛妹妹 2020-11-29 08:59

I was just wondering if there is a need of TimeSpan in java.util so that I can define how much hours,minutes and seconds are there in between these two times.

4条回答
  •  遥遥无期
    2020-11-29 09:44

    In Java 8 a proper time library has been added to the standard API (this is based heavily on JodaTime).

    In it there are two classes that you can use to indicate a period:

    1. Duration which indicates a seconds or nanoseconds length of a timespan.
    2. Period which indicates a more user-friendly difference, stored as 'x years and y months etc'.

    A detailed explanation of the difference between them can be found in the Java tutorial

提交回复
热议问题