Java Date to String DateToString(Date fecha, String formato)

Here you can find the source of DateToString(Date fecha, String formato)

Description

Date To String

License

Apache License

Declaration

public static String DateToString(Date fecha, String formato) throws Exception 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String DateToString(Date fecha, String formato) throws Exception {
        if (nullToBlank(fecha).equals("")) {
            return "";
        }/*from   w w  w.  j a va 2  s .c om*/
        SimpleDateFormat df = new SimpleDateFormat(formato);
        return df.format(fecha);
    }

    /**
     * retorna una cadena vacia en caso de ser null
     */
    public static String nullToBlank(Object texto) {
        try {
            if (texto == null) {
                return "";
            }
            if (texto.toString().trim().equals("null")) {
                return "";
            }
            return texto.toString().trim();
        } catch (Exception e) {
            return "";
        }

    }
}

Related

  1. dateToString(Date date, String sPattern)
  2. dateToString(Date date, String strFormat)
  3. datetostring(Date dateInst)
  4. DateToString(Date Expression)
  5. dateToString(Date fecha)
  6. dateToString(Date pd_fecha)
  7. dateToString(Date pDate, String pFormat)
  8. dateToString(Date pdttValue, String pstrDateFormat)
  9. DateToString(Date thisdate, Locale locale)