Java DateTimeFormatter formatDateTime(Date dateTime)

Here you can find the source of formatDateTime(Date dateTime)

Description

Format a date/time to YYYY-MM-dd HH:mm:ss format

License

Open Source License

Parameter

Parameter Description
dateTime The date/time

Return

The formatted date/time

Declaration

@Deprecated
public static String formatDateTime(Date dateTime) 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.time.LocalDateTime;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/* w  ww.  j a v a2  s  . c  o  m*/
     * A formatter for generating date/time strings. The output format is {@code YYYY-MM-DD HH:mm:ss}.
     */
    @Deprecated
    private static SimpleDateFormat dateTimeFormatter = null;
    /**
     * For formatting LocalDateTime - dates and parsing date time strings
     */
    private static java.time.format.DateTimeFormatter displayDateTimeFormatter = null;

    /**
     * Format a date/time to YYYY-MM-dd HH:mm:ss format
     * @param dateTime The date/time
     * @return The formatted date/time
     */
    @Deprecated
    public static String formatDateTime(Date dateTime) {
        return dateTimeFormatter.format(dateTime);
    }

    /**
     * Format a date/time to YYYY-MM-dd HH:mm:ss format
     * @param dateTime The date/time
     * @return The formatted date/time
     */
    public static String formatDateTime(LocalDateTime dateTime) {
        return displayDateTimeFormatter.format(dateTime);
    }

    /**
     * Format a date/time to YYYY-MM-dd HH:mm:ss format
     * @param dateTime The date/time
     * @return The formatted date/time
     */
    @Deprecated
    public static String formatDateTime(Calendar dateTime) {
        return formatDateTime(dateTime.getTime());
    }
}

Related

  1. formatDate(long date)
  2. formatDate(long milli)
  3. formatDate(long timestamp)
  4. formatDate(long timestamp)
  5. formatDateAndTime(String dateAndTime)
  6. formatDateTime(long milis)
  7. formatISOUTCDateTime(long timestamp)
  8. formatNow(String format)
  9. formatTime(long milliSeconds)