Java Hour Format formatDate(Date date, String format)

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

Description

format Date

License

Open Source License

Declaration

public static String formatDate(Date date, String format) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {

    public static String formatDate(Date date, String format) {
        if (format == null || "".equals(format)) {
            format = "yyyy-MM-dd HH:mm:ss";
        }/*from  w w  w. j  av  a2s.  c  o m*/
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }

    public static String formatDate(long timestamp, String format) {
        if (format == null || "".equals(format)) {
            format = "yyyy-MM-dd HH:mm:ss";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(new Date(timestamp));
    }
}

Related

  1. formatDate(Date date, boolean time, boolean csv)
  2. formatDate(Date date, boolean withTime)
  3. formatDate(Date date, String dateFormat)
  4. formatDate(Date date, String expression)
  5. formatDate(Date date, String format)
  6. formatDate(Date date, String format)
  7. formatDate(Date date, String format)
  8. formatDate(Date date, String format)
  9. formatDate(Date date, String format, Locale locale)