| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (key_duration.xml)

This example Java source code file (key_duration.xml) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

api, apis, datetime, duration, durations, iso-8859-1, joda-time, note, nulls, readableduration, the, thus, within

The key_duration.xml Java example source code

<?xml version="1.0" encoding="ISO-8859-1"?>


  <title>Java date and time API - Duration
  <author>Stephen Colebourne


<section name="Duration">

A <i>duration in Joda-Time represents a duration of time measured in milliseconds.
The duration is often obtained from an <a href="key_interval.html">interval.
Durations are a very simple concept, and the implementation is also simple.
They have no <a href="key_chronology.html">chronology or time zone, and consist
solely of the millisecond duration.
Durations can be added to an <a href="key_instant.html">instant, or to either
end of an interval to change those objects.
In datetime maths you could say:
      instant  +  duration  =  instant
Durations implement <code>Comparable which compares the lengths of the two durations.


<section name="Using Durations in Joda-Time">
Within Joda-Time a duration is represented by the
<a href="apidocs/org/joda/time/ReadableDuration.html">ReadableDuration interface.
There is one implementation of the interface provided:
<li>Duration -
An immutable implementation</li>
The code can be used in various ways:
DateTime start = new DateTime(2004, 12, 25, 0, 0, 0, 0);
DateTime end = new DateTime(2005, 1, 1, 0, 0, 0, 0);

// duration in ms between two instants
Duration dur = new Duration(start, end);

// calc will be the same as end
DateTime calc =;
Note that the interface <code>ReadableDuration should not be used like the collections API.
The interface only contains the core subset of the operations.
Instead, you should usually refer directly to the implementation class in your APIs.

<subsection name="Nulls">
Joda-Time defines a null duration as zero length.
Thus, when a method is defined as taking a <code>ReadableDuration, passing null in
will be the same as passing in a zero length duration.



Other Java examples (source code examples)

Here is a short list of links related to this Java key_duration.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.