Date and Time API
Less than 1 minuteNoteLanguageJava
- Starting time:
1 Jan 1970; starting year for a calendar:1900 - Old APIs in
java.util- Keep timestamp in a
longvalue in milliseconds - Is mutable
java.util.Dateis deprecatedjava.util.Calendar- An abstract class
- The standard calendar:
GregorianCalendar
java.util.TimeZone- An abstract class
- Keep timestamp in a
- New APIs: Joda Date and Time APIs in
java.time- Date and time are separated
- Keep timestamp in seconds and nano seconds
- Is immutable
Instant- A timestamp
LocalDate,LocalTime,LocalDateTime,ZonedDateTime,ZoneIDDuration,Period- A
Durationis a simple measure of time along the time-line in nanoseconds - A
Periodexpresses an amount of time in units meaningful to humans, such as years or days between()
- A
Month,DayOfWeek,Year,YearMonth,MonthDay,OffsetTime,OffsetDateTime,ZoneOffset- Methods
of- static factory methodnow- static factory methodparse- static factory method focused on parsingget- gets the value of somethingis- checks if something is truewith- the immutable equivalent of a setterplus- adds an amount to an objectminus- subtracts an amount from an objectto- converts this object to another typeat- combines this object with another
- All calculations should check for numeric overflow and throw either an
ArithmeticExceptionor aDateTimeException DateTimeFormatterofPattern(String pattern)- doc
ChronoField
