How do I use Joda-Time’s DateMidnight class?

The org.joda.time.DateMidnight class represent a date time information with the time value set to midnight. The following snippet show you how to instantiate this class.

package org.kodejava.example.joda;

import org.joda.time.DateMidnight;

import java.util.Date;

public class DateMidnightDemo {
    public static void main(String[] args) {
        //
        // Create DateMidnight object of the current system dateMidnight.
        //
        DateMidnight dateMidnight = new DateMidnight();
        System.out.println("dateMidnight = " + dateMidnight);

        //
        // Create DateMidnight object by year, month and day.
        //
        dateMidnight = new DateMidnight(2012, 1, 1);
        System.out.println("dateMidnight = " + dateMidnight);

        //
        // Create DateMidnight object from JDK's Date milliseconds.
        //
        Date date = new Date();
        dateMidnight = new DateMidnight(date.getTime());
        System.out.println("dateMidnight = " + dateMidnight);
    }
}
Wayan Saryada

Wayan Saryada

A programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, JPA, etc. If you need help on Java programming you can hire me on Fiverr.
Wayan Saryada

Leave a Reply