Here you can find the source of getTimeZone(String timezone, String time, DateFormat format)
public static String getTimeZone(String timezone, String time, DateFormat format)
//package com.java2s; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseException; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public static String getTimeZone(String timezone, String time, DateFormat format) { try {//from w w w. j a v a2s. c o m time = time.trim(); if (time.endsWith(":00")) { time = time.substring(0, time.length() - 3) + "00"; } Date date = parseDateStringToDate(format, time); Calendar ca = Calendar.getInstance(); ca.clear(); ca.setTimeInMillis(date.getTime()); format.setTimeZone(TimeZone.getTimeZone(timezone)); time = Format(format, ca.getTime()); format.setTimeZone(TimeZone.getDefault()); } catch (Exception e) { } return time; } public static Date parseDateStringToDate(DateFormat format, String dateString) { if (format != null) { synchronized (format) { try { return format.parse(dateString); } catch (ParseException e) { return null; } } } else { // String message = "format is null,the dataString is " + // dateString; return null; } } public static Date parseDateStringToDate(DateFormat format, String time, TimeZone timeZone) { synchronized (format) { try { format.setTimeZone(timeZone); return format.parse(time); } catch (ParseException e) { return null; } } } public static String Format(DateFormat format, Timestamp time) { synchronized (format) { String t = ""; try { t = format.format(time); } catch (Exception e) { return t; } return t; } } public static String Format(DateFormat format, Date time) { synchronized (format) { String t = ""; try { t = format.format(time).replace("24:", "00:"); } catch (Exception e) { return t; } return t; } } public static String Format(DateFormat format, long time) { synchronized (format) { String t = ""; try { t = format.format(time); } catch (Exception e) { return t; } return t; } } }