Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Java 8 java time package: converting Duration to miliseconds

 
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recently I needed to write a utility based on new java time package that was introduced in java 8. IMHO this package is very well designed and implemented, flexible and robust. One of the things that I needed to get is to be able to implement some functionality for duration or interval - period of time between two instants. In particular I needed to extract a number of milliseconds from instance of Duration class. In Joda package there is an Interval class that provides such functionality (method toDurationMillis()), but class Duration does not provide such method out of the box. So I wrote one. It is not a complicated method but might save some time to other fellow programmers out there. So here is the utility class. It has another method which is a wrapper for sleep() method that "swallows" the Interrupted exception. It might be useful as well.

 
reply
    Bookmark Topic Watch Topic
  • New Topic