Loading topic
java.time. This chapter explains what went wrong with the old classes, so you can see why the new ones work the way they do.2 min readLocalDate is a Java object that holds a calendar date: a year, a month, and a day. It has no time of day and no time zone. Use it for things like birthdays, holidays, and due dates, where only the day matters.1 min readLocalTime.2 min readLocalDate, which holds a calendar date, and LocalTime, which holds a time of day. Many real tasks need both at once. A dentist appointment, for example, happens on July 1 at 9:30. LocalDateTime is a class that holds a date and a time of day together in one object.1 min readLocalDate for them.2 min readLocalDate, LocalTime, and LocalDateTime. Those types describe a date or time the way a wall calendar or a clock face does. They don't say where in the world that time happens. Sometimes you need to name one exact moment that is the same for everyone on Earth. For t2 min readLocalDateTime, have no idea where in the world they are. "9:00 on July 1" happens at a different moment in London than in Tokyo. To pin a time to a real moment, Java needs to know the place. Two classes describe that place: ZoneId and ZoneOffset.2 min readLocalDateTime holds a date and a clock time, such as "July 1, 9:00". It does not know where in the world that time applies. 9:00 in New York and 9:00 in Tokyo are different moments, 13 hours apart.2 min readZonedDateTime. It knows the full rules of a time zone, such as "America/New_York". Sometimes you don't need those rules. You only need to say exactly when something happened, in a form any other system can read. OffsetDateTime covers that case.2 min readDuration, covered in the previous chapter, for hours, minutes, and seconds. Use Period for calendar dates.2 min readPeriod gives you years, months, and days as separate parts. A Duration gives you hours, minutes, and seconds. ChronoUnit gives you a single total count in the unit you choose.1 min readplusDays and some counting. Java gives you a shortcut instead.1 min readZonedDateTime knows the rules for each zone, so it handles the jumps for you. You still need to know what it does.2 min readjava.util.Date, java.util.Calendar, and the java.sql date classes. You may need to pass a java.time value to a library that only accepts a Date, or read a Calendar that an old method returns. Java 8 added conversion methods to the old classes so you can move be1 min read