Java Calendar to String CalendarToString(Calendar fecha, String formato)

Here you can find the source of CalendarToString(Calendar fecha, String formato)

Description

Calendar To String

License

Apache License

Declaration

public static String CalendarToString(Calendar fecha, String formato) throws Exception 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    public static String CalendarToString(Calendar fecha, String formato) throws Exception {
        if (nullToBlank(fecha).equals("")) {
            return "";
        }//from   ww  w  .  j  a v a2s .  c  om
        SimpleDateFormat df = new SimpleDateFormat(formato);
        return df.format(fecha.getTime());
    }

    /**
     * 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. calendarToString(Calendar calendar)
  2. calendarToString(Calendar calendar)
  3. calendarToString(Calendar calendar)
  4. calendarToString(Calendar calendar, String template)
  5. calendarToString(Calendar date, boolean transformToLocalTime)
  6. calendarToXSDString(Calendar cal, String fmt)
  7. dateToCalendar(final String date)
  8. dateToString(Calendar date, DateFormat format)
  9. getDateString(Calendar cal)