Java Data Type How to - Convert java.util.Date to any local date in certain timezone








Question

We would like to know how to convert java.util.Date to any local date in certain timezone.

Answer

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
//w  ww.  j a  v a  2s  . c om
public class Main {

  public static void main(String[] args) {
    System.out.println(asLocalDateIn(new Date(), ZoneId.systemDefault()));
  }

  public static LocalDate asLocalDateIn(Date date, ZoneId timeZone) {
    return date.toInstant().atZone(timeZone).toLocalDate();
  }
}

The code above generates the following result.