1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| LocalDate date = LocalDate.of(2014, 3, 18); int year = date.getYear(); Month month = date.getMonth(); int day = date.getDayOfMonth(); DayOfWeek dow = date.getDayOfWeek(); int len = date.lengthOfMonth();
boolean leap = date.isLeapYear(); System.out.println(leap);
LocalDate today = LocalDate.now();
year = date.get(ChronoField.YEAR);
LocalTime time = LocalTime.of(13, 45, 20); int hour = time.getHour(); int minute = time.getMinute(); int second = time.getSecond();
date = LocalDate.parse("2014-03-18"); time = LocalTime.parse("13:45:20");
LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); LocalDateTime dt2 = LocalDateTime.of(date, time); LocalDateTime dt3 = date.atTime(13, 45, 20); LocalDateTime dt4 = date.atTime(time); LocalDateTime dt5 = time.atDate(date);
Instant.ofEpochSecond(0);
Instant.ofEpochSecond(2, 1_000); Instant.now().toEpochMilli();
Duration d1 = Duration.between(time, time.plusHours(1)); System.out.println(d1.getSeconds());
Period tenDays = Period.between(LocalDate.of(2014, 3, 8), LocalDate.of(2014, 3, 18)); System.out.println(tenDays.getDays());
Duration threeMinutes = Duration.ofMinutes(3); threeMinutes = Duration.of(3, ChronoUnit.MINUTES);
Period nineDays = Period.ofDays(9); Period threeWeeks = Period.ofWeeks(3); Period twoYearsSixMonthsOneDay = Period.of(2, 6, 1); System.out.println(dt1.plus(twoYearsSixMonthsOneDay));
LocalDateTime localDateTime = LocalDate.now().atTime(0, 0, 0); long beginOfDay = localDateTime.toEpochSecond(ZoneOffset.of("+08:00"));
System.out.println(localDateTime); System.out.println(beginOfDay);
|