Joda Time

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » Joda Time 
Joda-Time
License:Apache Software License
URL:http://joda-time.sourceforge.net/
Description:Joda-Time provides a quality replacement for the Java date and time classes.
Package NameComment
org.joda.example.time
org.joda.time org.joda.time package

Provides support for dates, times, time zones, durations, intervals, and partials. This package aims to fully replace the Java Date, Calendar, and TimeZone classes. This implementation covers both the Gregorian/Julian calendar system and the ISO8601 standard. Additional calendar systems and extensions can be created as well.

The ISO8601 standard is the international standard for dates, times, durations, and intervals. It defines text representations, the first day of the week as Monday, and the first week in a year as having a Thursday in it. This standard is being increasingly used in computer interchange and is the agreed format for XML. For most uses, the ISO standard is the same as Gregorian, and is thus the preferred format.

Interfaces

The main API concepts are defined by interfaces:

  • ReadableInstant - an instant in time
  • ReadableDateTime - an instant in time with field accessors such as dayOfWeek
  • ReadablePartial - a definition for local times that are not defined to the millisecond, such as the time of day
  • ReadableDuration - a duration defined in milliseconds
  • ReadablePeriod - a time period defined in fields such as hours and minutes
  • ReadableInterval - a period of time between two instants
  • ReadWritableInstant - an instant that can be modified
  • ReadWritableDateTime - a datetime that can be modified
  • ReadWritablePeriod - a time period that can be modified
  • ReadWritableInterval - an interval that can be modified

These define the public interface to dates, times, periods, intervals and durations. As with java.util.Date and Calendar, the design is millisecond based with an epoch of 1970-01-01. This should enable easy conversions.

Implementations

The basic implementation of the ReadableInstant interface is Instant. This is a simple immutable class that stores the millisecond value and integrates with Java Date and Calendar. The class follows the definition of the millisecond instant fully, thus it references the ISO-8601 calendar system and UTC time zone. If you are dealing with an instant in time but do not know, or do not want to specify, which calendar system it refers to, then you should use this class.

The main implementation class for datetimes is the DateTime class. This implements the ReadableDateTime interface, providing convenient methods to access the fields of the datetime. Conversion methods allow integration with the Java Date and Calendar classes.

Like Instant, DateTime is immutable, and it can be used safely in a multi-threaded environment. In order to be fully immutable, key clases are declared as final. Abstract superclasses are provided should you need to define your own implementations.

The concrete implementations of the ReadWritable... interfaces are named the same as their immutable counterparts, but with a "Mutable" prefix. For example, MutableDateTime implements ReadWritableDateTime, making datetime editing easy. Note that it is possible to use the immutable DateTime for modifying datetimes, however each modification method returns a new instance of DateTime.

Interface usage

The interfaces in Joda-Time are not designed to operate in the same way as those in the Java Collections Framework (List/Map/Set etc). The Joda-Time interfaces represent a core subset of the functionality available via the actual classes. Thus, much of the work of an application will probably use methods on the class, not on the interface. Your application must determine whether it should define dates in terms of the interfaces, or in terms of the classes.

The interfaces provide simple methods to access an instance of the immutable class, which is implemented either via typecast or object creation. Thus, if you hold a reference to a ReadableInstant, and you call the method toDateTime(), the same instance will be returned (typecast) if it already was a DateTime.

Chronologies and Fields

In order to enable the package to be easily extended, each field of the datetime, such as the month, is calculated by an implementation of DateTimeField. Likewise, duration fields are calculated by specialized DurationField instances. If desired, users can write their own implementations to retrieve an unusual field from the millisecond value.

The datetime and duration fields that together represent a calendar system are grouped into a Chronology. The chronology represents all the information to convert from a millisecond value to human understandable fields in a specific calendar system. Chronologies are provided for ISO, Gregorian/Julian (GJ), Buddhist, Coptic and Ethiopic. More implementations are sought from the community.

The chronology and field classes are singletons. This design results in a low overhead on the date and time classes. The Java Calendar class performs poorly because it has many internal fields that are constantly kept in sync. This design only calculates fields when required, resulting in lightweight and simple date time classes.

When reviewing the library for the first time, it is easy to mistake the number of classes with complexity. The library is in fact clearly divided between user packages and implementation packages in the javadoc. Most users will should not need to be concerned with the back-end implementation.

Partials

Partials are like instants, except they do not completely specify a point in time. The main interface is ReadablePartial.

The main implementations are:

  • LocalTime - A class storing a local time without a date
  • LocalDate - A class storing a local date without a time
  • LocalDateTime - A class storing a local datetime
  • Partial - A class storing any combination of datetime fields, such as dayOfMonth and dayOfWeek
For consistency, the API of each partial class is similar to that of an instant class.

All partial implementations represent a local time, in other words without a time zone. Thus, to convert a partial to an instant (which does contain a time zone) requires adding a zone.

Formatting

Formatting is provided by the format subpackage. Comprehensive support is provided for outputting dates and times in multiple formats. A pattern similar to Java SimpleDateFormat can be used, but a more advanced programmatic technique is available via the builder classes.

org.joda.time.base org.joda.time.chrono package

Implementation package providing abstract and base time classes.

Provides abstract implementations of the Readable* interfaces. The Abstract* classes hold no fields and have no final methods. They can be used by anyone wanting to implement the interface. The Base* classes extend the Abstract* classes to provide fields for the standard way to implement the class.

If you intend to implement a Readable* interface yourself, please consider extending either the Abstract* or Base* class in this package.

org.joda.time.chrono org.joda.time.chrono package

Package containing the chronology classes which define the calendar systems.

This package contains all of the chronology implementations within the library. A chronology represents all the rules of a calendar system. Applications will create chronologies using the static factory methods on each specific Chronology class - getInstance. The currently provided chronology implementations are:

  • ISO
  • GJ (GregorianJulian)
  • Gregorian
  • Julian
  • Buddhist
  • Coptic
  • Ethiopic
  • Islamic

The package also contains all of the specialised field implementations. These classes are package scoped, along with various other chronology helper classes. The package scoped classes (which are not shown in the javadoc) do not form part of the public API of Joda-Time and may change at any time.

org.joda.time.chrono.gj
org.joda.time.convert org.joda.time.convert package

Implementation package providing conversion between date and time objects.

Provides support for converting objects into instants and durations. Converters are used internally by many of the standard classes, like DateTime. Most applications have no need to use these classes directly.

org.joda.time.field org.joda.time.field package

Implementation package providing abstract and standard field classes.

Provides DateTimeField and DurationField implementations and support. Applications will only use this package directly if they want to write their own DateTimeField implementation.

org.joda.time.format org.joda.time.format package

Provides printing and parsing support for instants and durations. This package contains simple and advanced classes for formatting.

Formatters are defined by interfaces, and instances are obtained from factory classes. Most datetime formatters can be obtained from DateTimeFormat and ISODateTimeFormat. More advanced formatters can be built by using DateTimeFormatterBuilder.

Similarly there are also classes for parsing and printing periods. Most period formatters can be obtained from the factory classes PeriodFormat and ISOPeriodFormat. More advanced formatters can be built by using PeriodFormatterBuilder.

org.joda.time.tz org.joda.time.tz package

Implementation package supporting the time zones.

Provides support for implementing time zones. {@link org.joda.time.DateTimeZone} uses these classes internally, but most applications need not use them directly.

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.