alvinalexander.com | 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 alvinalexander.com "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"?>

<document>

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

 <body>

<section name="Duration">

<p>
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.
</p>
<p>
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.
</p>
<p>
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:
<source>
      instant  +  duration  =  instant
</source>
</p>
<p>
Durations implement <code>Comparable which compares the lengths of the two durations.
</p>

</section>

<section name="Using Durations in Joda-Time">
<p>
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:
<ul>
<li>Duration -
An immutable implementation</li>
</ul>
</p>
<p>
The code can be used in various ways:
<source>
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 = start.plus(dur);
</source>
</p>
<p>
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.
</p>

<subsection name="Nulls">
<p>
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.
</p>
</subsection>

</section>

</body>
</document>

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, alvinalexander.com
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.