Java Hour Format formatDate(Date date, String pattern)

Here you can find the source of formatDate(Date date, String pattern)

Description

format Date

License

Apache License

Declaration

public static String formatDate(Date date, String pattern) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String DEFAULTFORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String formatDate(Date date, String pattern) {
        if (date == null)
            return "";
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);//  ww w .  j a v a  2s  . c  o  m
        return formatCalendar(calendar, pattern);
    }

    public static String formatDate(Date date) {
        return formatDate(date, DEFAULTFORMAT);
    }

    public static String formatCalendar(Calendar calendar) {
        return formatCalendar(calendar, DEFAULTFORMAT);
    }

    public static String formatCalendar(Calendar calendar, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        //sdf.setTimeZone(TimeZone.getTimeZone(timeZone));
        return sdf.format(calendar.getTime());
    }
}

Related

  1. formatDate(Date date, String format)
  2. formatDate(Date date, String format)
  3. formatDate(Date date, String format)
  4. formatDate(Date date, String format, Locale locale)
  5. formatDate(Date date, String patter)
  6. formatDate(Date date, String pattern)
  7. formatDate(Date date, String timeFormat, String timeZone)
  8. formatDate(Date date, StringBuffer buffer)
  9. formatDate(Date date, TimeZone tz)