Java SQL Date Convert dateToString(java.util.Date date, String dateFmt)

Here you can find the source of dateToString(java.util.Date date, String dateFmt)

Description

date To String

License

Apache License

Declaration

public static String dateToString(java.util.Date date, String dateFmt) 

Method Source Code

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

import java.text.SimpleDateFormat;

public class Main {
    public static String dateToString(java.util.Date date, String dateFmt) {
        String strTemp = null;//  w ww . j  a va  2 s .c  om
        if (date != null) {
            String dtFmt = dateFmt;
            if (null == dtFmt)
                dtFmt = "yyyy-MM-dd";
            SimpleDateFormat formatter = new SimpleDateFormat(dtFmt);
            strTemp = formatter.format(date);
        }
        return strTemp;
    }

    public static String dateToString(java.sql.Date date) {
        return dateToString(date, null);
    }

    public static String format(java.util.Date date) {
        return date == null ? "" : format(date, "yyyy-MM-dd");
    }

    public static String format(java.util.Date date, String pattern) {
        return date == null ? "" : new SimpleDateFormat(pattern).format(date);
    }
}

Related

  1. dateToString(Date date)
  2. dateToString(Date date, String format)
  3. dateToString(java.sql.Date d)
  4. dateToString(java.sql.Date data)
  5. dateToString(java.sql.Date datee)
  6. to2GMTString(final Date tsStart, final Date tsEnd)
  7. to_char(Date date, String format)
  8. to_char(Date date, String format)
  9. toBigDecimal(@Nullable final Date value)