You want to find today’s date and/or time.
Invoke the appropriate builder to obtain a LocalDate
, LocalTime
, or LocalDateTime
object and call its toString()
method.
In full-scale applications, it’s recommended to pass a Clock
instance into all the now()
methods.
You want to provide better formatting for date and time objects.
Use java.time.format.DateTimeFormatter
.
You need to convert among dates/times, YMDHMS, epoch seconds, or some other numeric value.
Use the appropriate date/time factory or retrieval methods.
You need to convert user input into java.time
objects.
Use a parse()
method.
You need to compute the difference between two dates.
Use the static method Period.between()
to find the difference between two LocalDates
.
You need to add or subtract a fixed period to or from a date.
Create a past or future date by using a locution such as LocalDate.plus(Period.ofDays(N));
.
You need to deal with recurring dates, for example, the third Wednesday of every month.
Use the TemporalAdjusters
class.
You need to deal with the old Date and Calendar classes.
Assuming you have code using the original java.util.Date
and java.util.Calendar
, you can convert values as needed using conversion methods.