Java Hour Format formatDateTime(Date dateTime)

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

Description

format Date Time

License

Apache License

Declaration

public static String formatDateTime(Date dateTime) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static SimpleDateFormat dateSdf = new SimpleDateFormat("yyyyMMdd");
    private static SimpleDateFormat dateTimeSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String formatDateTime(Date dateTime) {
        return dateTimeSdf.format(dateTime);
    }/* www  . j a  v a  2 s  .c  om*/

    public static String formatDateTime(String dateTime) {
        return dateTimeSdf.format(parseDate(dateTime));
    }

    public static Date parseDate(String date) {
        try {
            return dateSdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. formatDateTime(Date date)
  2. formatDateTime(Date date)
  3. formatDateTime(Date date)
  4. formatDatetime(Date date)
  5. formatDateTime(Date date)
  6. formatDateTime(Date myDate)
  7. formatDateTime(final Calendar cal)
  8. formatDateTime(final Date dat)
  9. formatDateTime(final Date date)