Java Calendar to String calendarToString(Calendar calendar)

Here you can find the source of calendarToString(Calendar calendar)

Description

Convert a Gregorian calendar object to string representation

License

Open Source License

Parameter

Parameter Description
calendar a parameter

Return

the string representation or empty string if calendar is null

Declaration


public static String calendarToString(Calendar calendar) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.SimpleDateFormat;

import java.util.Calendar;

public class Main {
    private static final SimpleDateFormat fmt = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    /**/*w  w w .  j a  va 2  s  .c  om*/
     * Convert a Gregorian calendar object to string representation
     * @param calendar
     * @return the string representation or empty string if calendar is null
     */
    //@author A0112115A
    public static String calendarToString(Calendar calendar) {
        if (calendar == null) {
            return "";
        }
        return fmt.format(calendar.getTime());
    }

    /**
     * Convert a Gregorian calendar object to string representation
     * with a given format
     * @param calendar
     * @return the string representation or empty string if calendar is null
     */
    //@author A0112115A
    public static String calendarToString(Calendar calendar, SimpleDateFormat format) {
        if (calendar == null) {
            return "";
        }
        return format.format(calendar.getTime());
    }
}

Related

  1. calendarToString(Calendar cal)
  2. calendarToString(Calendar cal)
  3. calendarToString(Calendar cal, String format)
  4. calendarToString(Calendar calendar)
  5. calendarToString(Calendar calendar)
  6. calendarToString(Calendar calendar, String template)
  7. calendarToString(Calendar date, boolean transformToLocalTime)
  8. CalendarToString(Calendar fecha, String formato)
  9. calendarToXSDString(Calendar cal, String fmt)