Time consts in Java?

前端 未结 13 659
遇见更好的自我
遇见更好的自我 2020-12-23 15:45

Is there a Java package with all the annoying time constants like milliseconds/seconds/minutes in a minute/hour/day/year? I\'d hate to duplicate something like that.

13条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 16:24

                  60 * 1000 miliseconds in 1 minute
                         60     seconds in 1 minute
                          1      minute in 1 minute
                       1/60       hours in 1 minute
                  1/(60*24)        days in 1 minute
              1/(60*24*365)       years in 1 minute
    1/(60*24*(365 * 4 + 1))     4 years in 1 minute
                                                    * 60            is in 1 hour
                                                    * 60 * 24       is in 1 day
                                                    * 60 * 24 * 365 is in 1 year
                                                etc.
    

    Create them yourself, I guess, is the easiest. You can use the Date and Calendar classes to perform calculations with time and dates. Use the long data type to work with large numbers, such as miliseconds from 1 Januari 1970 UTC, System.currentTimeMillis().

提交回复
热议问题