Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package common; import java.sql.Date; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.Calendar; import java.util.Locale; import org.joda.time.DateTime; import org.joda.time.Days; /** * * @author GloomySunday */ public class CommonFunction { public static boolean isEqualDate(Date date1, Date date2) { Calendar calendarDate1 = Calendar.getInstance(); calendarDate1.setTime(date1); Calendar calendarDate2 = Calendar.getInstance(); calendarDate2.setTime(date2); return calendarDate1.get(Calendar.DATE) == calendarDate2.get(Calendar.DATE) && calendarDate1.get(Calendar.MONTH) == calendarDate2.get(Calendar.MONTH) && calendarDate1.get(Calendar.YEAR) == calendarDate2.get(Calendar.YEAR); } public static boolean isGreaterThanDate(Date date1, Date date2) { DateTime d1 = new DateTime(date1); DateTime d2 = new DateTime(date2); return d1.withTimeAtStartOfDay().isAfter(d2.withTimeAtStartOfDay()); } public static Date increaseDateByOneDay(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1); return new Date(calendar.getTimeInMillis()); } public static int calculateDayBetweenTwoDate(Date date1, Date date2) { return Days.daysBetween(new DateTime(date1), new DateTime(date2)).getDays(); } public static int getDateOfMonth(Date date) { DateTime dateTime = new DateTime(date); return dateTime.dayOfMonth().getMaximumValue(); } public static String convertDoubleToMoney(double value) { DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.US); DecimalFormatSymbols symbols = df.getDecimalFormatSymbols(); symbols.setGroupingSeparator('.'); df.setDecimalFormatSymbols(symbols); return df.format(value); } }