Java Hour Format formatDate(Date src, String formatPattern)

Here you can find the source of formatDate(Date src, String formatPattern)

Description

format Date

License

Apache License

Declaration

public static String formatDate(Date src, String formatPattern) 

Method Source Code


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

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String formatDate(Date src, String formatPattern) {
        if (src == null) {
            return "";
        }/*from w w  w  .  j  ava  2 s . c om*/
        DateFormat fmt = new SimpleDateFormat(formatPattern);
        return fmt.format(src);
    }

    public static String formatDate(Date src) {
        return formatDate(src, "yyyy-MM-dd HH:mm:ss");
    }

    public static String formatDate() {
        return formatDate(new Date(), "yyyy-MM-dd");
    }

    public static String formatDate(String formatPattern) {
        return formatDate(new Date(), formatPattern);
    }
}

Related

  1. formatDate(Date date, String pattern)
  2. formatDate(Date date, String timeFormat, String timeZone)
  3. formatDate(Date date, StringBuffer buffer)
  4. formatDate(Date date, TimeZone tz)
  5. formatDate(Date dateString)
  6. formatDate(final Date date, final String pattern)
  7. formatDate(final Date date, String pattern)
  8. formatDate(final String date)
  9. formatDate(java.util.Date date, String pattern)