public static void main(String[] args) { String month; System.out.println("java Days"); System.out.println("----------------"); System.out.print("Enter the month: "); Scanner inputScanner = new Scanner(System.in); month = inputScanner.next(); int returned_monthNum = Days.getmonthNum(month); if (returned_monthNum == 0) { System.out.println("Invalid month"); } System.out.println(month + " is month number " + returned_monthNum); int year = 2013; int numDays = 0; switch (month) { case "JAN": case "january": case "MAR": case "march": case "MAY": case "may": case "JUL": case "july": case "AUG": case "august": case "OCT": case "october": case "DEC": case "december": numDays = 31; break; case "APR": case "april": case "JUNE": case "june": case "SEPT": case "september": case "NOV": case "november": numDays = 30; break; case "FEB": case "february": if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) numDays = 29; else numDays = 28; break; default: System.out.println("Invalid month."); break; } System.out.println("It has " + numDays + " days."); }
public static void main(String[] args) { for (Days d : Days.values()) ; Days[] d2 = Days.values(); System.out.println(d2[2]); }
/** * Converts this period in weeks to a period in days assuming a 7 day week. * * <p>This method allows you to convert between different types of period. However to achieve this * it makes the assumption that all weeks are 7 days long. This may not be true for some unusual * chronologies. However, it is included as it is a useful operation for many applications and * business rules. * * @return a period representing the number of days for this number of weeks * @throws ArithmeticException if the number of days is too large to be represented */ public Days toStandardDays() { return Days.days(FieldUtils.safeMultiply(getValue(), DateTimeConstants.DAYS_PER_WEEK)); }
public void testToStandardDays() { Minutes test = Minutes.minutes(60 * 24 * 2); Days expected = Days.days(2); assertEquals(expected, test.toStandardDays()); }
/** * Converts this period in hours to a period in days assuming a 24 hour day. * * <p>This method allows you to convert between different types of period. However to achieve this * it makes the assumption that all days are 24 hours long. This is not true when daylight savings * time is considered, and may also not be true for some unusual chronologies. However, it is * included as it is a useful operation for many applications and business rules. * * @return a period representing the number of whole days for this number of hours */ public Days toStandardDays() { return Days.days(getValue() / DateTimeConstants.HOURS_PER_DAY); }