JODA-TIME / NOTES</>↗Joda-Time06 Feb 2012
The code below show you how to use the Months class to calculate the different in months between two dates. package org.kodejava.joda; import org.joda.time.DateMidnight; import org.joda.time.LocalDate; import org.joda.time.Months; import java.util.Date; public class MonthsBetweenDemo { public static void main(String[] args) { // Creates an instance of start and end dates. DateMidnight start = new DateMidnight("2021-01-01"); DateMidnight […]
JODA-TIME / NOTES</>↗Joda-Time02 Feb 2012
This code snippet show you how to convert Joda-Time’s DateTime object into JDK’s java.util.Calendar or java.util.Date object. To convert DateTime to java.util.Date we use the toDate() method and to convert to java.util.Calendar we use the toCalendar() method. package org.kodejava.joda; import org.joda.time.DateTime; import java.util.Calendar; import java.util.Date; import java.util.Locale; public class DateTimeToDateCalendarDemo { public static void main(String[] […]
JODA-TIME / NOTES</>↗Joda-Time02 Feb 2012
Using the Joda-Time library can simplify the date calculation process. For instance, we can add or subtract some days, weeks, months or year easily. There are a plus and minus method for this operation. For instance if you want to add 9 weeks to date object you can do something like date.plusWeeks(9). package org.kodejava.joda; import […]
JODA-TIME / NOTES</>↗Joda-Time02 Feb 2012
The example show you how to format the string representation of a date. In Joda we can use the DateTime‘s class toString() method. The method accept the pattern of the date format and the locale information. package org.kodejava.joda; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import java.util.Locale; public class FormattingDemo { // Define the date format pattern. private […]
JODA-TIME / NOTES</>↗Joda-Time02 Feb 2012
In Joda-Time the date and time information are divided into fields. The following example show you some fields that can be obtained from the DateTime object. For example to get the day of the year we use the getDayOfYear() method and to get the day of week we can use the getDayOfWeek() method. package org.kodejava.joda; […]
JODA-TIME / NOTES</>↗Joda-Time02 Feb 2012
This example will give you the first day of the next month from the current system date. In the example we use the MutableDateTime class. MutableDateTime is a datetime class whose value can be modified. In the code snippet we start by creating an instance of MutableDateTime class. We add 1 month from the current […]