List of usage examples for java.time YearMonth of
public static YearMonth of(int year, int month)
From source file:Main.java
public static void main(String[] args) { YearMonth y = YearMonth.of(2013, 9); System.out.println(y); }
From source file:Main.java
public static void main(String[] args) { YearMonth y = YearMonth.of(2013, Month.JANUARY); System.out.println(y); }
From source file:Main.java
public static void main(String[] args) { YearMonth y = YearMonth.now(); YearMonth s = y.with(YearMonth.of(2013, 01)); System.out.println(s);/* w ww.jav a 2 s . co m*/ }
From source file:Main.java
public static void main(String[] args) { for (Month month : Month.values()) { YearMonth ym = YearMonth.of(2014, month); System.out.printf("%s: %d days%n", month, ym.lengthOfMonth()); }// w ww . j a v a 2 s .c om }
From source file:Main.java
public static void main(String[] args) { YearMonth y = YearMonth.now(); long s = y.until(YearMonth.of(1990, Month.JANUARY), ChronoUnit.YEARS); System.out.println(s);//from w w w . jav a2 s . c o m }
From source file:Main.java
public static void main(String[] args) { YearMonth y = YearMonth.now(); Temporal s = y.adjustInto(YearMonth.of(1990, Month.JANUARY)); System.out.println(s);/*from w ww .j av a 2 s. c om*/ }
From source file:Main.java
public static void main(String[] args) { YearMonth yearMonth = YearMonth.of(2014, 6); System.out.println(yearMonth.query(new SchoolHolidayQuery())); // false System.out.println(YearMonth.of(2014, Month.JULY).query(new SchoolHolidayQuery())); // true System.out.println(YearMonth.of(2014, 8).query(new SchoolHolidayQuery())); // true }
From source file:Main.java
public static void main(String[] argv) { YearMonth currentYearMonth = YearMonth.now(); System.out.printf("Days in month year %s: No of days: %s \n", currentYearMonth, currentYearMonth.lengthOfMonth()); YearMonth creditCardExpiry = YearMonth.of(2018, Month.FEBRUARY); System.out.printf("Your credit card expires on %s: No of days: %s \n", creditCardExpiry, creditCardExpiry.lengthOfMonth()); }
From source file:MonthsInYear.java
public static void main(String[] args) { int year = 0; if (args.length <= 0) { System.out.printf("Usage: MonthsInYear <year>%n"); throw new IllegalArgumentException(); }/*from w w w. j a va2s .c o m*/ try { year = Integer.parseInt(args[0]); } catch (NumberFormatException nexc) { System.out.printf("%s is not a properly formatted number.%n", args[0]); throw nexc; // Rethrow the exception. } try { Year test = Year.of(year); } catch (DateTimeException exc) { System.out.printf("%d is not a valid year.%n", year); throw exc; // Rethrow the exception. } System.out.printf("For the year %d:%n", year); for (Month month : Month.values()) { YearMonth ym = YearMonth.of(year, month); System.out.printf("%s: %d days%n", month, ym.lengthOfMonth()); } }
From source file:com.mycompany.flooringmaster.Controllers.Controller.java
private String getFileName(boolean acceptAnything, String date) { DateFormat dateFormat = new SimpleDateFormat("MMddyyyy"); Date currentDate = new Date(); String strDate = "Orders_" + dateFormat.format(currentDate) + ".txt"; DateFormat yearFormat = new SimpleDateFormat("YYYY"); int currentYear = Integer.parseInt(yearFormat.format(currentDate)); boolean notValid = true, answer = true; while (notValid) { try {//from www.jav a 2s .c om String response = io.getUserInputString("Use today's date for the order? (y/n): "); if (acceptAnything && response.equals("")) { return date; } else if (response.equalsIgnoreCase("yes") || response.equalsIgnoreCase("y")) { answer = true; notValid = false; } else if (response.equalsIgnoreCase("no") || response.equalsIgnoreCase("n")) { answer = false; notValid = false; } else { notValid = true; } } catch (Exception ex) { } } if (!answer) { String fullDate; int year, month, day; YearMonth yearMonthObject; boolean valid = false; do { do { fullDate = io.getUserInputString("Date (MMDDYYYY): "); fullDate = fullDate.replaceAll("[^\\d]", ""); } while (fullDate.length() != 8); month = Integer.parseInt(fullDate.substring(0, 2)); day = Integer.parseInt(fullDate.substring(2, 4)); year = Integer.parseInt(fullDate.substring(4, 8)); yearMonthObject = YearMonth.of(year, month); if (day > yearMonthObject.lengthOfMonth() || day < 1) { valid = false; } else if (month > 12 || month < 1) { valid = false; } else if (year > currentYear || year < 2000) { valid = false; } else { valid = true; } } while (!valid); strDate = "Orders_" + String.format("%02d", month) + String.format("%02d", day) + year + ".txt"; } return strDate; }