java 11 cannot find symbol DateTimeFormatter
This error occur due to import statements are missing..
import java.time.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class DateTimeAPI
{
public static void main(String[] args)
{
LocalDate date2 = LocalDate.of(2020, Month.NOVEMBER, 10);
LocalTime time2 = LocalTime.of(19, 23);
LocalDateTime dt2 = LocalDateTime.of(date2, time2);
System.out.println(date2.format(DateTimeFormatter.ISO_LOCAL_DATE));
System.out.println(time2.format(DateTimeFormatter.ISO_LOCAL_TIME));
System.out.println(dt2.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
var formatter2 = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss");
System.out.println(dt2.format(formatter2));
System.out.println(LocalDate.now());
System.out.println(LocalTime.now());
System.out.println("Local date time " +LocalDateTime.now());
System.out.println("Zoned Date time" +ZonedDateTime.now());
LocalDate date1=LocalDate.of(2020,Month.NOVEMBER,10);
System.out.println("local date "+date1.now());
LocalTime time1=LocalTime.of(10,55);
LocalDateTime ldt2=LocalDateTime.of(2020,Month.NOVEMBER,10,10,55,55);
System.out.println("localdatetime "+ldt2);
System.out.println("day of Year "+ldt2.getDayOfYear());
System.out.println("Get Month Of Year"+ldt2.getDayOfMonth());
//custom format
var dt=LocalDateTime.of(date1,time1);
var formatter1 = DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss");
System.out.println(dt.format(formatter1));
}
}
Comments
Post a Comment