Java Time Format time2String(Date time, DateFormat dateFormat)

Here you can find the source of time2String(Date time, DateFormat dateFormat)

Description

time String

License

Open Source License

Declaration

public synchronized static String time2String(Date time, 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_TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");

    public synchronized static String time2String(Date time, DateFormat dateFormat) {
        if (time == null)
            return null;
        return dateFormat.format(time);
    }/* www.  j a va2s.c  o m*/

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

    public static String time2String(Date time) {
        if (time == null)
            return null;
        return date2String(time, DEFAULT_TIME_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. string2long(String sourceTime, String dataFormat)
  2. stringDateTimeFormat(String dt2Format)
  3. stringTimeToLongTime(String time, String format)
  4. stringToTime(String format, String sDate)
  5. time2Date(Integer time, String format)
  6. timeFormatDate(Date d)
  7. timeFormatNano(long delta)
  8. timeFormatter()
  9. timestr(String format, long secs)