Duration in Java is a part of the java.time package which represents a time-based amount of time, such as '34.5 seconds' or '2 hours'. It is used to define a duration between two points in time and can be expressed in days, hours, minutes, seconds, and nanoseconds. The Duration class is often used in conjunction with other time-based classes, such as LocalDateTime and ZonedDateTime.
Here is an example of how to use Duration in Java:
import java.time.Duration;
import java.time.LocalDateTime;
public class DurationExample {
public static void main(String[] args) {
LocalDateTime start = LocalDateTime.now();
LocalDateTime end = start.plusHours(2).plusMinutes(30);
Duration duration = Duration.between(start, end);
System.out.println("Duration: " + duration.toHours() + " hours and " + duration.toMinutesPart() + " minutes.");
}
}
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?