Here you can find the source of formatDate(Date d, TimeZone tz)
public static String formatDate(Date d, TimeZone tz)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String formatDate(Date d, TimeZone tz) { SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm"); sdf.setTimeZone(tz);/*from w w w .jav a2 s . co m*/ return sdf.format(d) + dateOffset(d, tz); } public static String dateOffset(Date d, TimeZone tz) { String offset = ""; try { int mins = tz.getOffset(d.getTime()) / (60 * 1000); int hours = mins / 60; int min = mins % 60; String zero = (min < 10) ? "0" : ""; String plus = (mins >= 0) ? "+" : ""; offset = " GMT " + plus + Integer.toString(hours) + ":" + zero + Integer.toString(min); } catch (Exception e) { } return offset; } }