java - Is it the last day of the month? -
what want happen - if date (that given parameters) equal last day of month, want cost increased 10%. i.e if dayoftravel = last day of month
public static double returnjourneycost(int journeyid, int dayoftravel, int monthoftravel, int yearoftravel){ cost = double.parsedouble(xmlload.load(journeyid, 3)); return cost; }
using old jdk-stuff answer might like:
public static boolean islastdayofmonth(int year, int month, int day) { gregoriancalendar gcal = new gregoriancalendar(year, month - 1, day); gcal.add(calendar.date, 1); return (gcal.get(calendar.day_of_month) == 1); }
in java 8 (better because avoids implicit reference system timezone):
public static boolean islastdayofmonth(int year, int month, int day) { localdate date = localdate.of(year, month, day); return date.lengthofmonth() == day; }
Comments
Post a Comment