List of usage examples for java.time Year now
public static Year now()
From source file:Main.java
public static void main(String[] args) { Year y = Year.now(); System.out.println(y); }
From source file:Main.java
public static void main(String[] args) { Year currentYear = Year.now(); Year twoThousand = Year.of(2000); boolean isLeap = currentYear.isLeap(); // false int length = currentYear.length(); // 365 // sixtyFourth day of 2014 (2014-03-05) LocalDate date = Year.of(2014).atDay(64); System.out.println("year: currentYear: " + currentYear); System.out.println("year: twoThousand: " + twoThousand); System.out.println("year: isLeap: " + isLeap); System.out.println("year: length: " + length); System.out.println("year: date: " + date); }
From source file:Main.java
public static void main(String[] args) { Month month = Month.valueOf("January".toUpperCase()); LocalDate date = Year.now().atMonth(month).atDay(12); System.out.println(date);//from w w w .jav a 2 s . co m }
From source file:Main.java
public static void main(String[] args) { Year y1 = Year.of(2014); System.out.println(y1);/*from w w w . jav a 2s. c om*/ Year y2 = y1.minusYears(1); System.out.println(y2); Year y3 = y1.plusYears(1); System.out.println(y3); Year y4 = Year.now(); System.out.println(y4); if (y1.isLeap()) { System.out.println(y1 + " is a leap year."); } else { System.out.println(y1 + " is not a leap year."); } }
From source file:Main.java
public static void main(String[] args) { Month month = Month.valueOf("March".toUpperCase()); System.out.printf("For the month of %s:%n", month); LocalDate date = Year.now().atMonth(month).atDay(1).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); Month mi = date.getMonth();//w w w . ja v a 2 s.c o m while (mi == month) { System.out.printf("%s%n", date); date = date.with(TemporalAdjusters.next(DayOfWeek.MONDAY)); mi = date.getMonth(); } }
From source file:Main.java
public static void main(String[] args) { Month month = Month.valueOf("MARCH"); int day = 10; LocalDate date = LocalDate.of(Year.now().getValue(), month, day); // Invoking the query without using a lambda expression. Boolean isFamilyVacation = date.query(new FamilyVacations()); // Invoking the query using a lambda expression. Boolean isFamilyBirthday = date.query(FamilyBirthdays::isFamilyBirthday); if (isFamilyVacation.booleanValue() || isFamilyBirthday.booleanValue()) System.out.printf("%s is an important date!%n", date); else/*from www . j av a 2 s .co m*/ System.out.printf("%s is not an important date.%n", date); }
From source file:Main.java
public static void main(String[] args) { Month month = null;/*w w w .j a v a2 s. c om*/ LocalDate date = null; DateTimeFormatter format; String out = null; month = Month.valueOf("May".toUpperCase()); date = Year.now().atMonth(month).atDay(12); LocalDate nextPayday = date.with(new PaydayAdjuster()); format = DateTimeFormatter.ofPattern("yyyy MMM d"); out = date.format(format); System.out.printf("Given the date: %s%n", out); out = nextPayday.format(format); System.out.printf("the next payday: %s%n", out); }
From source file:Superstitious.java
public static void main(String[] args) { Month month = null;//from w ww.j a v a 2 s. com LocalDate date = null; if (args.length < 2) { System.out.printf("Usage: Superstitious <month> <day>%n"); throw new IllegalArgumentException(); } try { month = Month.valueOf(args[0].toUpperCase()); } catch (IllegalArgumentException exc) { System.out.printf("%s is not a valid month.%n", args[0]); throw exc; // Rethrow the exception. } int day = Integer.parseInt(args[1]); try { date = Year.now().atMonth(month).atDay(day); } catch (DateTimeException exc) { System.out.printf("%s %s is not a valid date.%n", month, day); throw exc; // Rethrow the exception. } System.out.println(date.query(new FridayThirteenQuery())); }
From source file:ListMondays.java
public static void main(String[] args) { Month month = null;/* w w w .ja v a 2 s . c o m*/ if (args.length < 1) { System.out.printf("Usage: ListMondays <month>%n"); throw new IllegalArgumentException(); } try { month = Month.valueOf(args[0].toUpperCase()); } catch (IllegalArgumentException exc) { System.out.printf("%s is not a valid month.%n", args[0]); throw exc; // Rethrow the exception. } System.out.printf("For the month of %s:%n", month); LocalDate date = Year.now().atMonth(month).atDay(1).with(TemporalAdjusters.firstInMonth(DayOfWeek.MONDAY)); Month mi = date.getMonth(); while (mi == month) { System.out.printf("%s%n", date); date = date.with(TemporalAdjusters.next(DayOfWeek.MONDAY)); mi = date.getMonth(); } }
From source file:org.smigo.message.MessageHandler.java
public void addNewYearNewsMessage(Optional<AuthenticatedUser> optionalUser, int year, List<Plant> plants, Locale locale) {/*from ww w. j a v a2s . co m*/ final List<Integer> validYears = Arrays.asList(Year.now().getValue(), Year.now().plusYears(1).getValue()); if (!optionalUser.isPresent() || !validYears.contains(year) || plants.size() < 10) { optionalUser.ifPresent(u -> log.info("Not adding new year news message for:" + u.getUsername())); return; } final AuthenticatedUser user = optionalUser.get(); final MessageAdd message = new MessageAdd(); final String text = messageSource.getMessage("msg.useraddedyearmessage", new Object[] { user.getUsername(), year }, locale); message.setText(text); message.setSubmitterUserId(1); message.setLocale(locale.toLanguageTag()); messageDao.addMessage(message); }