We would like to know how to convert date/calendar in different timezones.
import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; //from ww w . j ava 2s . co m public class Main { public static void main(String[] args) { Date d = new Date(); System.out.println(d); DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone("Australia/Sydney")); System.out.println(df.format(d)); df.setTimeZone(TimeZone.getTimeZone("Europe/London")); System.out.println(df.format(d)); } }
The code above generates the following result.