Java Program to convert LocalDate to java.util.Date in UTC

Java 8Object Oriented ProgrammingProgramming

Set the LocalDate to the current date −

LocalDate date = LocalDate.now();

Convert to java.util.Date in UTC −

Date.from(date.atStartOfDay().toInstant(ZoneOffset.UTC))

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);
      System.out.println("Date (UTC) = "+Date.from(date.atStartOfDay().toInstant(ZoneOffset.UTC)));
   }
}

Output

Date = 2019-04-19
Date (UTC) = Fri Apr 19 05:30:00 IST 2019
raja
Published on 24-Apr-2019 14:58:37
Advertisements