Java Hour Format formatDateTime(final Date date)

Here you can find the source of formatDateTime(final Date date)

Description

Format the Date using pattern "yyyy-MM-dd HH:mm:ss"

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String formatDateTime(final Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**/*w w w  .  jav a 2s . co m*/
     * Format the Date using pattern "yyyy-MM-dd HH:mm:ss"
     *
     * @param date
     * @return
     */
    public static String formatDateTime(final Date date) {
        return formatDateTime(date, null);
    }

    public static String formatDateTime(final Date date, final String defaultValue) {
        if (date == null) {
            return defaultValue;
        }
        return dateTimeFormat.format(date);
    }
}

Related

  1. formatDateTime(Date date)
  2. formatDateTime(Date dateTime)
  3. formatDateTime(Date myDate)
  4. formatDateTime(final Calendar cal)
  5. formatDateTime(final Date dat)
  6. formatDateTime(java.util.Date d)
  7. formatDateTime(java.util.Date date)
  8. formatDateTime(java.util.Date date)
  9. formatDateTime(java.util.Date paramDate)