JodaTime MutableDateTime

Overview

By default
DateTime
class in Joda-Time API is immutable. However Joda-Time gives an option to create Mutable version of
DateTime
called
MutableDateTime
.

This article describes the usage of
MutableDateTime
.

  1. Modify Fields
  2. Add Fields To MutableDateTime
  3. Perform Rounding Operations

Modify Fields

Use setter methods to modify fields in
MutableDateTime


Add Fields To MutableDateTime

Fields can be added to
MutableDateTime
using the following ways:

  1. Using add..() methods to directly add the value of field
  2. Adding Duration: Using the following 3 ways:
    1. Using DurationFieldType
    2. Directly adding Duration
    3. Adding Duration in Millis
  3. Adding Period


Perform Rounding Operations

Joda-Time API provides supports for rounding off
DateTime
to the nearest field.

In particular, the following types of rounding are supported:

  • Floor: Round to the nearest floor
  • Ceiling; Round to the nearest ceiling
  • Half Floor: Round to the floor if the value of the field is closer to floor or exactly halfway. Else round to ceiling
  • Half Ceiling: Round to the floor if the value of the field is closer to floor or exactly halfway. Else round to ceiling
  • No Rounding


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

Leave a Reply

Your email address will not be published. Required fields are marked *