CORE API / CATATAN</>↗Core API14 Feb 2012
The following code snippet convert a string representation of a date into a java.util.Date object and the timezone is set to GMT. To parse the string so that the result is in GMT you must set the TimeZone of the DateFormat object into GMT. package org.kodejava.joda; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import […]
JODA-TIME / CATATAN</>↗Joda-Time06 Feb 2012
The following code snippet show you how to get days between two dates. You can use the Days.daysBetween() method and pass the dates you want to calculate. This method return a Days object. To get the number in days you call the getDays() method. package org.kodejava.joda; import org.joda.time.DateMidnight; import org.joda.time.Days; import org.joda.time.LocalDate; public class DaysBetweenDemo […]
JODA-TIME / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]