List of usage examples for java.time Period getDays
public int getDays()
From source file:Main.java
public static void main(String[] args) { Period p = Period.ofMonths(1); System.out.println(p.getDays()); }
From source file:Main.java
public static void main(String[] args) { LocalDate firstDate = LocalDate.of(2013, 5, 17); LocalDate secondDate = LocalDate.of(2015, 3, 7); Period period = Period.between(firstDate, secondDate); System.out.println(period);/*from ww w. j a v a2s .c o m*/ int days = period.getDays(); // 18 int months = period.getMonths(); // 9 int years = period.getYears(); // 4 boolean isNegative = period.isNegative(); // false }
From source file:Main.java
public static void main(String[] args) { Period employmentPeriod = period(LocalDate.of(2000, Month.FEBRUARY, 1)); int years = employmentPeriod.getYears(); int months = employmentPeriod.getMonths(); int days = employmentPeriod.getDays(); System.out.println(years);//from w ww. ja va 2 s .com System.out.println(months); System.out.println(days); }
From source file:Main.java
public static void main(String[] args) { LocalDate today = LocalDate.now(); LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1); LocalDate nextBDay = birthday.withYear(today.getYear()); //If your birthday has occurred this year already, add 1 to the year. if (nextBDay.isBefore(today) || nextBDay.isEqual(today)) { nextBDay = nextBDay.plusYears(1); }// w w w . j a v a 2 s . c o m Period p = Period.between(today, nextBDay); long p2 = ChronoUnit.DAYS.between(today, nextBDay); System.out.println("There are " + p.getMonths() + " months, and " + p.getDays() + " days until your next birthday. (" + p2 + " total)"); }
From source file:Main.java
public static void main(String[] args) { Period p = Period.between(LocalDate.of(2009, Month.JANUARY, 21), LocalDate.of(2019, Month.JANUARY, 21)); System.out.println(p.get(ChronoUnit.DAYS)); LocalDate today = LocalDate.now(); LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1); LocalDate nextBDay = birthday.withYear(today.getYear()); nextBDay = nextBDay.plusYears(1);//from w w w . jav a2s . c o m p = Period.between(today, nextBDay); long p2 = ChronoUnit.DAYS.between(today, nextBDay); System.out.println(p.getMonths() + " months"); System.out.println(p.getDays() + " days"); }
From source file:com.omertron.slackbot.functions.Meetup.java
/** * Format the MeetUp list into a list of Slack Attachments, up to a certain number of days ahead * * @param daysAhead// w ww. j av a2 s . c om * @param detailed * @return */ public static Map<LocalDateTime, SlackAttachment> getMeetupsDays(int daysAhead, boolean detailed) { LocalDate now = LocalDate.now(); Map<LocalDateTime, SlackAttachment> results = new HashMap<>(); Period diff; for (MeetupDetails md : MEETUPS) { // Correct for BST LocalDateTime meetTime = md.getMeetupTime().plusHours(1); diff = Period.between(now, meetTime.toLocalDate()); if (diff.getDays() <= daysAhead) { LOG.info("Add: Days: {} - {} - {}", diff.getDays(), meetTime.format(DT_FORMAT), md.getName()); results.put(meetTime, makeSlackAttachment(md, detailed)); } else { LOG.info("Skip: Days: {} - {} - {}", diff.getDays(), meetTime.format(DT_FORMAT), md.getName()); } } return results; }
From source file:edu.lternet.pasta.portal.search.TemporalList.java
private static int calculateMonths(String beginDate, String endDate) { int durationInMonths; LocalDate localBeginDate = LocalDate.parse(beginDate); LocalDate localEndDate = LocalDate.parse(endDate); Period duration = Period.between(localBeginDate, localEndDate); int years = duration.getYears(); int months = duration.getMonths(); int days = duration.getDays(); durationInMonths = ((years * 12) + months); if (days > 15) { durationInMonths++;/* w ww . j av a2s . co m*/ } System.out.printf("Begin Date: %s, End Date: %s\n", beginDate, endDate); System.out.printf("The duration is %d years, %d months and %d days\n", duration.getYears(), duration.getMonths(), duration.getDays()); System.out.printf("The total duration in months is %d\n\n", durationInMonths); return durationInMonths; }
From source file:com.omertron.slackbot.listeners.GoogleSheetsListener.java
public static void createGameNightMessage(SlackSession session, SlackChannel msgChannel) { LocalDate now = LocalDate.now(); Period diff = Period.between(now, sheetInfo.getGameDate()); switch (diff.getDays()) { case 0://from ww w .j ava2s . c o m session.sendMessage(msgChannel, "Game night is tonight!! :grin:", GoogleSheetsListener.createGameInfo()); break; case 1: session.sendMessage(msgChannel, "Game night is tomorrow! :smile:", GoogleSheetsListener.createGameInfo()); break; default: session.sendMessage(msgChannel, GoogleSheetsListener.createSimpleNightMessage(sheetInfo, diff)); break; } }
From source file:com.omertron.slackbot.listeners.GoogleSheetsListener.java
/** * Create a simple formatted message about the future game night * * @param sheetInfo SheetInfo/* w w w. ja va2 s . co m*/ * @param diff Days to next game night * @return Slack Prepared Message */ public static SlackPreparedMessage createSimpleNightMessage(SheetInfo sheetInfo, Period diff) { SlackPreparedMessage.Builder spm = new SlackPreparedMessage.Builder().withUnfurl(false); StringBuilder sb = new StringBuilder("Game night is "); sb.append(sheetInfo.getFormattedDate("EEEE, d MMMM")).append(", still ").append(diff.getDays()) .append(" days away\n"); if (StringUtils.isBlank(sheetInfo.getGameChooser())) { sb.append("There is no-one to chose the next game!!! :astonished:"); } else { if ("All".equalsIgnoreCase(sheetInfo.getGameChooser())) { sb.append("The group is choosing :open_mouth:"); } else if ("Other".equalsIgnoreCase(sheetInfo.getGameChooser())) { sb.append("It's someone else's turn to choose :open_mouth:"); } else { sb.append("It's *").append(sheetInfo.getGameChooser()).append("'s* turn to choose"); } if (sheetInfo.getNextGameId() <= 0) { // There's no game ID, this could be because there's no game selected or an error reading if (StringUtils.isBlank(sheetInfo.getGameName())) { // No game chosen LOG.error("SheetInfo READ:\n{}", ToStringBuilder.reflectionToString(sheetInfo, ToStringStyle.MULTI_LINE_STYLE)); sb.append(", but no game has been selected yet :angry:\n"); } else { // Error with reading the sheet or with google's API sb.append(" and *").append(sheetInfo.getGameName()).append("* has been chosen.\n"); } } else { sb.append(" and *").append(SlackBot.formatLink(Constants.BGG_LINK_GAME + sheetInfo.getNextGameId(), sheetInfo.getGameName())).append("* has been picked.\n"); } } // Who's attending? if (sheetInfo.getPlayers().isEmpty()) { sb.append("No-one has said they are going!"); } else { sb.append(sheetInfo.getNameList(", ")).append(" are attending"); } spm.withMessage(sb.toString()); return spm.build(); }
From source file:agendapoo.Model.Atividade.java
@Override public int compareTo(Atividade o) { Period p = Period.between(o.data, data); if (p.getDays() == 0) return this.horaInicio.compareTo(o.getHoraInicio()); return p.getDays(); }