java date change timezone

java

To change the time zone of a java.util.Date object, you can use the setTimeZone method of the Calendar class. Here is an example:

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class Main {
  public static void main(String[] args) {
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
    date = cal.getTime();
    System.out.println(date);
  }
}

This will set the time zone of the Date object to Pacific Standard Time (PST).