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.joda;
import org.joda.time.DateMidnight;
import org.joda.time.format.DateTimeFormat;
public class DateMidnightDemo {
public static void main(String[] args) {
// Create DateMidnight object of the current system date.
DateMidnight date = new DateMidnight();
System.out.println("date = " + date);
// Or using the now().
date = DateMidnight.now();
System.out.println("date = " + date);
// Create DateMidnight object by year, month and day.
date = new DateMidnight(2021, 10, 29);
System.out.println("date = " + date);
// Create DateMidnight object from milliseconds.
date = new DateMidnight(System.currentTimeMillis());
System.out.println("date = " + date);
// Parse a date from string.
date = DateMidnight.parse("2021-10-29");
System.out.println("date = " + date);
// Parse a date from string of specified patter.
date = DateMidnight.parse("29/10/2021",
DateTimeFormat.forPattern("dd/MM/yyyy"));
System.out.println("date = " + date);
}
}
The result of our code snippet:
date = 2021-10-29T00:00:00.000+08:00
date = 2021-10-29T00:00:00.000+08:00
date = 2021-10-29T00:00:00.000+08:00
date = 2021-10-29T00:00:00.000+08:00
date = 2021-10-29T00:00:00.000+08:00
date = 2021-10-29T00:00:00.000+08:00
Maven Dependencies
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.12.5</version>
</dependency>
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024