Java Date to String dateTime2String(Date dateTime, DateFormat dateFormat)

Here you can find the source of dateTime2String(Date dateTime, DateFormat dateFormat)

Description

date Time String

License

Open Source License

Declaration

public synchronized static String dateTime2String(Date dateTime, DateFormat dateFormat) 

Method Source Code

//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

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

    public synchronized static String dateTime2String(Date dateTime, DateFormat dateFormat) {
        if (dateTime == null)
            return null;
        return dateFormat.format(dateTime);
    }/*from w  w  w.  ja va  2  s .  c o  m*/

    public static String dateTime2String(Date dateTime, String dateFormat) {
        if (dateTime == null)
            return null;
        return date2String(dateTime, dateFormat);
    }

    public static String dateTime2String(Date dateTime) {
        if (dateTime == null)
            return null;
        return date2String(dateTime, DEFAULT_DATETIME_FORMAT);
    }

    public synchronized static String date2String(Date date, DateFormat dateFormat) {
        if (date == null)
            return null;
        return dateFormat.format(date);
    }

    public static String date2String(Date date, String dateFormat) {
        if (date == null)
            return null;
        return date2String(date, new SimpleDateFormat(dateFormat));
    }

    public static String date2String(Date date) {
        if (date == null)
            return null;
        return date2String(date, DEFAULT_DATE_FORMAT);
    }
}

Related

  1. date2StringISO(Date date)
  2. date2StringMD(Date date)
  3. date2StringPattern(Date value, String pattern)
  4. Date2StringSec(Date date)
  5. datetime(Date date)
  6. dateTimeISO(final java.util.Date date)
  7. dateTimeToZero(Date date)
  8. dateTo14String(Date date)
  9. dateToBOMCStrDate(Date date)