Java Program to convert LocalDate to java.util.Date by timezone offset

Java 8Object Oriented ProgrammingProgramming

Set the LocalDate to now −

LocalDate date = LocalDate.now();

Now, set the TimeZone offset −

ZoneOffset timeZone = ZoneOffset.UTC;

Convert the LocalDate to java.util.Date −

Date.from(date.atStartOfDay().toInstant(timeZone))

Example

 Live Demo

import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      LocalDate date = LocalDate.now();
      System.out.println("Date = "+date);
      ZoneOffset timeZone = ZoneOffset.UTC;
      System.out.println(Date.from(date.atStartOfDay().toInstant(timeZone)));
   }
}

Output

Date = 2019-04-19
Fri Apr 19 05:30:00 IST 2019
raja
Published on 24-Apr-2019 14:57:14
Advertisements