LocalDate yMd = LocalDate.of(2017, 4, 1)
System.out.println(yMd)
System.out.println(yMd.getYear())
System.out.println(yMd.getMonth())
System.out.println(yMd.getDayOfMonth())
System.out.println(yMd.getDayOfYear())
System.out.println(yMd.getDayOfWeek())
System.out.println(yMd.isLeapYear())
System.out.println(yMd.lengthOfMonth())
System.out.println(yMd.lengthOfYear())
System.out.println("==========================")
LocalDate today = LocalDate.now()
System.out.println(today)
System.out.println("==========================")
System.out.println(yMd.get(ChronoField.YEAR))
System.out.println(yMd.get(ChronoField.MONTH_OF_YEAR))
System.out.println(yMd.get(ChronoField.DAY_OF_MONTH))
System.out.println(yMd.get(ChronoField.DAY_OF_WEEK))
System.out.println("==========================")
LocalTime hMs = LocalTime.of(17, 50, 10)
System.out.println(hMs)
System.out.println(hMs.getHour())
System.out.println(hMs.getMinute())
System.out.println(hMs.getSecond())
System.out.println("==========================")
LocalDate parseDate = LocalDate.parse("2017-04-05")
LocalTime parseTime = LocalTime.parse("18:10:10")
System.out.println(parseDate)
System.out.println(parseTime)
System.out.println("==========================")
LocalDateTime yMdhMs = LocalDateTime.of(yMd, hMs)
LocalDateTime athMs = yMd.atTime(hMs)
LocalDateTime atyMd = hMs.atDate(yMd)
System.out.println(athMs)
System.out.println(atyMd)
System.out.println(yMdhMs)
System.out.println("==========================")
LocalDate toDate = yMdhMs.toLocalDate()
LocalTime toTime = yMdhMs.toLocalTime()
System.out.println(toDate)
System.out.println(toTime)
System.out.println("==========================")
System.out.println(Instant.ofEpochSecond(3))
System.out.println(Instant.ofEpochSecond(2,1_000_000_000))
System.out.println("==========================")
Duration ofMin = Duration.ofMinutes(3)
Duration of = Duration.of(3, ChronoUnit.MINUTES)
System.out.println(ofMin)
System.out.println(of)
Period ofDay = Period.ofDays(10)
Period ofWeek = Period.ofWeeks(3)
Period yearMonthDay = Period.of(2, 6, 1)
System.out.println(ofDay)
System.out.println(ofWeek)
System.out.println(yearMonthDay)
System.out.println("==========================")
LocalDate editDate = LocalDate.of(2017, 4, 10)
System.out.println(editDate)
System.out.println(editDate.withYear(2020))
System.out.println(editDate.withMonth(7))
System.out.println(editDate.with(ChronoField.DAY_OF_MONTH,7))
System.out.println(editDate.plusWeeks(1))
System.out.println(editDate.minusWeeks(3))
System.out.println(editDate.plus(10,ChronoUnit.MONTHS))
System.out.println("==========================")
LocalDate tempDate = LocalDate.of(2017, 4, 6)
System.out.println(tempDate.with(nextOrSame(DayOfWeek.SUNDAY)))
System.out.println(tempDate.with(lastDayOfMonth()))
LocalDate lambdaDate = tempDate.with(temporal -> {
DayOfWeek dow = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK))
int dayToAdd = 1
if(dow == DayOfWeek.THURSDAY) dayToAdd = 3
else if(dow == DayOfWeek.WEDNESDAY) dayToAdd = 2
return temporal.plus(dayToAdd,ChronoUnit.DAYS)
})
System.out.println(lambdaDate)
System.out.println("==========================")
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:MM:ss")
LocalDateTime date = LocalDateTime.of(yMd, hMs)
String formatDate = dtf.format(date)
System.out.println(formatDate)
System.out.println("==========================")
DateTimeFormatter formatter =
new DateTimeFormatterBuilder()
.appendText(ChronoField.DAY_OF_MONTH)
.appendLiteral(".")
.appendText(ChronoField.MONTH_OF_YEAR)
.appendLiteral(".")
.appendText(ChronoField.YEAR)
.parseCaseInsensitive()
.toFormatter(Locale.ITALIAN)
System.out.println(formatter.format(date))
System.out.println("==========================")
ZoneId zoneId = TimeZone.getDefault().toZoneId()
System.out.println(zoneId)
2017-04-01
2017
APRIL
1
91
SATURDAY
false
30
2017
4
1
17:50:10
17
50
2017-04-05
2017-04-01T17:50:10
2017-04-01T17:50:10
2017-04-01
1970-01-01T00:00:03Z
PT3M
PT3M
P10D
P21D
2017-04-10
2020-04-10
2017-07-10
2017-04-07
2017-04-17
2017-03-20
2017-04-09
2017-04-30
Asia/Shanghai