Classes in the Date-Time API do not provide public constructors.
You create their objects by providing static factory methods named of(), ofXxx(), and from().
All classes, interfaces, and enums for the Date-Time API are in the java.time package and four of its subpackages:
The following snippet of code creates date-time objects representing a date, a time, and a combination of them with and without a time zone:
import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZonedDateTime; public class Main { public static void main(String[] args) { LocalDate dateOnly = LocalDate.now(); LocalTime timeOnly = LocalTime.now(); LocalDateTime dateTime = LocalDateTime.now(); ZonedDateTime dateTimeWithZone = ZonedDateTime.now(); System.out.println(dateOnly); System.out.println(timeOnly); System.out.println(dateTime); System.out.println(dateTimeWithZone); }//from www . j a va 2 s . co m }
Useful Datetime-Related Enums