Java version: 1.8 start
Importjava.time.LocalDate;ImportJava.time.LocalDateTime;ImportJava.time.LocalTime;ImportJava.time.ZonedDateTime;ImportJava.time.format.DateTimeFormatter;/*** Created by Frank*/ Public classCurrentdatetime { Public Static voidMain (string[] args) {localdate dnow=Localdate.now (); System.out.println (Dnow); LocalTime Tnow=Localtime.now (); System.out.println (Tnow); LocalDateTime Now=Localdatetime.now (); System.out.println (now); DateTimeFormatter DF= Datetimeformatter.ofpattern ("Yyyy/mm/dd"); System.out.println (Df.format (Localdatetime.now ())); System.out.println (Localdate.parse ("2016/11/28", DF)); DateTimeFormatter NTZ= Datetimeformatter.ofpattern ("D MMMM, yyyy h:mm a"); System.out.println (Zoneddatetime.now (). Format (NTZ)); }}
Run output:
2016-11-2817:11:34.1312016-11-28t17:11:34.1312016/11/282016-11-2828 November, 2016 5:11 pm
Java Classic instance: use Dateformatter to format date time