List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:Main.java
public static void main(String[] argv) { String ldStr = DateTimeFormatter.ISO_DATE.format(LocalDate.now()); System.out.println(ldStr);// w ww . j av a 2 s.c o m String odtStr = DateTimeFormatter.ISO_DATE.format(OffsetDateTime.now()); System.out.println(odtStr); String zdtStr = DateTimeFormatter.ISO_DATE.format(ZonedDateTime.now()); System.out.println(zdtStr); }
From source file:Main.java
public static void main(String[] argv) { System.out.println(getPreviousWorkingDay(LocalDate.now())); }
From source file:Main.java
public static void main(String[] args) { LocalDate startEmployment = LocalDate.of(2011, Month.FEBRUARY, 1); LocalDate today = LocalDate.now(); long numberOfDays = startEmployment.until(today, ChronoUnit.DAYS); System.out.println(String.format("%d", numberOfDays)); }
From source file:Main.java
public static void main(String[] argv) { LocalDate startEmployment = LocalDate.of(2010, Month.SEPTEMBER, 8); LocalDate today = LocalDate.now(); Period period = startEmployment.until(today); System.out.println("period = " + period); long numberOfDays = startEmployment.until(today, DAYS); System.out.println("numberOfDays = " + numberOfDays); }
From source file:Main.java
public static void main(String[] args) { DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM); System.out.println(dateFormatter.format(LocalDate.now())); // Current Local Date System.out.println(dateFormatter.parse("Jan 19, 2014").getClass().getName()); //java.time.format.Parsed System.out.println(dateFormatter.parse("Jan 19, 2014", LocalDate::from)); // Jan 19, 2014 }
From source file:Main.java
public static void main(String[] args) { LocalDate today = LocalDate.now(); LocalDate monday = today.with(previousOrSame(MONDAY)); LocalDate sunday = today.with(nextOrSame(SUNDAY)); System.out.println("Today: " + today); System.out.println("Monday of the Week: " + monday); System.out.println("Sunday of the Week: " + sunday); }
From source file:Main.java
public static void main(String[] argv) { List<DayOfWeek> list = new ArrayList<>(); for (Month month : Month.values()) { DayOfWeek day = LocalDate.now().withYear(2010).with(month).with(TemporalAdjusters.lastDayOfMonth()) .getDayOfWeek();//from w w w .j a v a 2 s. com list.add(day); } System.out.println(list); }
From source file:Main.java
public static void main(String[] args) { // the current date LocalDate currentDate = LocalDate.now(); // 2014-02-10 LocalDate tenthFeb2014 = LocalDate.of(2014, Month.FEBRUARY, 10); // months values start at 1 (2014-08-01) LocalDate firstAug2014 = LocalDate.of(2014, 8, 1); // the 65th day of 2010 (2010-03-06) LocalDate sixtyFifthDayOf2010 = LocalDate.ofYearDay(2010, 65); // times, e.g. 19:12:30.733 LocalTime currentTime = LocalTime.now(); // current time LocalTime midday = LocalTime.of(12, 0); // 12:00 LocalTime afterMidday = LocalTime.of(13, 30, 15); // 13:30:15 // 12345th second of day (03:25:45) LocalTime fromSecondsOfDay = LocalTime.ofSecondOfDay(12345); // dates with times, e.g. 2014-02-18T19:08:37.950 LocalDateTime currentDateTime = LocalDateTime.now(); // 2014-10-02 12:30 LocalDateTime secondAug2014 = LocalDateTime.of(2014, 10, 2, 12, 30); // 2014-12-24 12:00 LocalDateTime christmas2014 = LocalDateTime.of(2014, Month.DECEMBER, 24, 12, 0); // current (local) time in Los Angeles LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles")); // current time in UTC time zone LocalTime nowInUtc = LocalTime.now(Clock.systemUTC()); System.out.println("date/time creation: currentDate: " + currentDate); System.out.println("date/time creation: tenthFeb2014: " + tenthFeb2014); System.out.println("date/time creation: firstAug2014: " + firstAug2014); System.out.println("date/time creation: sixtyFifthDayOf2010: " + sixtyFifthDayOf2010); System.out.println("date/time creation: currentTime: " + currentTime); System.out.println("date/time creation: midday: " + midday); System.out.println("date/time creation: afterMidday: " + afterMidday); System.out.println("date/time creation: fromSecondsOfDay: " + fromSecondsOfDay); System.out.println("date/time creation: currentTimeInLosAngeles: " + currentTimeInLosAngeles); System.out.println("date/time creation: currentDateTime: " + currentDateTime); System.out.println("date/time creation: secondAug2014: " + secondAug2014); System.out.println("date/time creation: christmas2014: " + christmas2014); }
From source file:Main.java
public static void main(String[] args) { TemporalQuery<TemporalUnit> precision = TemporalQueries.precision(); System.out.println(LocalDate.now().query(precision)); // Days System.out.println(LocalTime.now().query(precision)); // Nanos System.out.println(YearMonth.now().query(precision)); // Months }
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);/* w w w. j a v a2 s . 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"); }