Firstly, we can obtain the current system milliseconds from the Joda-Time Instant class instance using the getMillis() method: Instant jodaInstant // implementation details Assert. But that's just the nature of it.Īs an alternative, you might consider just using Durations from the start (if possible) and not using Periods at all. While Java 8 adds much of Joda-Times functionality, we may want to use this option if we are on Java 7 or earlier. Note that #2 will print different values depending on the day the code runs. The code below is what I have and it currently sends the data to a. Note de côté: Joda Time utilise BEAUCOUP de indirections dans son API en tant que telle lecture de la Javadoc nexige pas seulement pour lire les méthodes dune classe, mais aussi de regarder la liste des méthodes héritées de tous les héritées des classes abstraites et des interfaces par exemple, un DateTime est aussi un ReadableInstant. outputs 810964.05 (when right now is "T13:36:43.880-06:00") I have a onClick that when clicked will get the current time and add a certain number of hours and minutes. (duration.toStandardSeconds().getSeconds() / 60.0) Otherwise, you can associate the Period with an instant in time and use a Duration: Period period = new Period(1, 6, 2, 2, 5, 4, 3, 100) ĭuration duration = period.toDurationFrom(new DateTime()) If any other component is non-zero, an exception will be thrown. ![]() The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the minutes component may be non-zero. : Cannot convert to Seconds as this period contains months and months vary in length Creates a new Minutes by parsing a string in the ISO8601 format 'PTnM'. However, if you do end up with a month value in your Period, you'll get (per the javadoc) an UnsupportedOperationException: Negative durations will affect the results of comparisons. (period.toStandardSeconds().getSeconds() / 60.0) For example, the duration between 14:00 and 15:00 on the same day is 1 hour (PT1H), but the duration between 15:00 and 14:00 is minus 1 hour (PT-1H). If you're guaranteed that your Period won't contain months (or higher), you can just use toStandardSeconds(): Period period = new Period(60, 40, 20, 500) That in mind, there are a few ways to approach this. ![]() However to achieve this it makes the assumption that all hours are 60 minutes and all minutes are 60 seconds.
0 Comments
Leave a Reply. |