Java Data Type How to - Convert a date to time with timezone offset








Question

We would like to know how to convert a date to time with timezone offset.

Answer

import java.util.Date;
import java.text.SimpleDateFormat;

class array05{
  public static void main(String[] args){
      SimpleDateFormat sf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
      System.out.println(sf.format(new Date()));
  }
}