localdate java code example
Example 1: format localdate java
LocalDate today = LocalDate.now();
String formattedDate = today.format(DateTimeFormatter.ofPattern("dd-MMM-yy"));
System.out.println(formattedDate);
Example 2: localdatetime java example
LocalDateTime current=LocalDateTime.now();
LocalDateTime dateTime=LocalDateTime.of(year,month,day,hour,minute,second);
dateTime.getHour();
dateTime.getDayOfWeek();
dateTime.isBefore(someOtherDateTime);
dateTime.toLocalDate();
dateTime.toLocalTime();
Example 3: java instant to localdatetime
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
Example 4: java date to localdate
LocalDate localDate = LocalDate.parse( new SimpleDateFormat("yyyy-MM-dd").format(date) );