Java Hour Format formatDate(Date d, TimeZone tz)

Here you can find the source of formatDate(Date d, TimeZone tz)

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Date d, TimeZone tz) 

Method Source Code

//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;
    }
}

Related

  1. formatCurrentTime()
  2. formatCurrentTime(final String format)
  3. formatDate(Calendar currentDate, String pattern)
  4. formatDate(Calendar time)
  5. formatDate(Date d, String pattern, TimeZone tz)
  6. formatDate(Date date, boolean includeTime)
  7. formatDate(Date date, boolean time, boolean csv)
  8. formatDate(Date date, boolean withTime)
  9. formatDate(Date date, String dateFormat)