Java JodaTime

Overview

Joda-Time
is a popular open source API for date and time manipulation.

Joda-Time is intuitive to use and is very elegantly designed. It has maps closely to the date-time domain concepts and has supports immutability. It has a wide variety of formatters which are thread safe. Support for TimeZones and multiple calendar systems is also provided.

Joda-Time API was a key driver in designing the
JSR 310
specification.

This is a How-To Guide for using the common features in Joda-Time API. Working code along with the expected output is described for each How-To.

The libraries used in the following examples are:

  • joda-time-2.3.jar
  • joda-convert-1.5.jar

The above libraries can be downloaded from Joda-Time
download page

    Date-Time Key Concepts

  1. Date Concepts
    1. Calendar
    2. Date
    3. Day
    4. Year
    5. Week
    6. Century Of Era
    7. Era
    8. Epoch
  2. Time Concepts
    1. TimeZone
    2. UTC Offset
    3. Clock Convention
    4. Hour Of Day
    5. Minute
    6. Second
    7. Milli-Second
  3. Joda-Time Specific Concepts
  4. Using DateTime

  5. Instantiate DateTime
  6. Get DateTime for current instant
  7. Get sub-elements of DateTime (e.g. year, month, hours, etc.)
  8. Perform arithmetic operations on DateTime like addition and substraction
  9. Update sub-elements of DateTime
  10. Get DateTime from String representation
  11. Compare two DateTime instances
  12. Convert DateTime to other representations like Milliseconds, JDK date, MutableDateTime, LocalDateTime and String
  13. Handling DateTime Exceptions
  14. Using DateTimeComparator

  15. Compare DateTime
  16. Compare Two DateTime instances considering only Date fields and ignoring TIme fields
  17. Compare Two DateTime instances considering only Time fields and ignoring Date fields
  18. Using Upper and Lower Limits for DateTime comparison
  19. Using DateTimeFormat

  20. Formatting Year Field
  21. Formatting Month Field
  22. Formatting Day Field
  23. Formatting Day Of Week Field
  24. Formatting Time Fields
  25. Using Formatting Styles: Short, Medium, Long, Full and Omit
  26. Define Styles Using Convenience Methods
  27. Custom Formatting of Date and Time Using DateTimeFormatterBuilder
  28. Using DateTimeZone

  29. Constructing DateTimeZone
  30. Get DateTimeZone Fields
  31. Using Duration

  32. Create Duration
  33. Perform Arithmetic Operations On Duration
  34. Convert Duration To Single Fields Periods like Days, Hours, Minutes and Seconds
  35. Using Instant

  36. Creating Instant
  37. Comparing Two Instants
  38. Get Sub-Fields of Instant
  39. Perform Arithmentic Operations On Instant like Addition, Subtraction and Repeated Addition
  40. Convert Instant To Other Representations Like DateTime, MutableDateTime,JDK Date and String
  41. Using Interval

  42. Construct An Interval
  43. Find Relationship Between Two Intervals (Gap, Adjoining, Overlap)
  44. Modify Interval Using Millis, Duration and Instant
  45. Using Single Field Periods

  46. Calculate Number Of Days
  47. Perform Arithmetic Operations On Single Field Periods
  48. Parsing ISO 8601 Format String For Period
  49. Convert To Other Standard Representations Like Duration, Hour, Minute And Second
  50. Using MutableDateTime

  51. Modify Fields
  52. Add Fields To MutableDateTime
  53. Perform Rounding Operations
  54. Using MutableInterval

  55. Modify Interval
  56. Using MutablePeriod

  57. Modify Period
  58. Miscellaneous Topics

  59. Convert 2 Digit Year To 4 Digit Year Using Pivot Year
  60. Get List Of Default Time Zones
  61. Verify Whether A Partial DateTime Is Contiguous

To start, click on the next arrow. If you find anything missing in the tutorials then please drop in your comments.

Leave a Comment