Java Calendar to String getString(Calendar calendar)

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

Description

Return String object from Calendar @param calendar.

License

Apache License

Parameter

Parameter Description
calendar a parameter

Declaration

public static String getString(Calendar calendar) 

Method Source Code

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

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

public class Main {
    /**//from  w  w w.jav a  2 s. com
     * Pattern default.
     */
    private static final String PATTERN_DEFAULT = "yyyy-MM-dd HH:mm:ss";

    /**
     * Return {@link String} object from {@link Calendar} @param calendar.
     * Use default pattern {@link #PATTERN_DEFAULT}
     * @param calendar
     * @return
     */
    public static String getString(Calendar calendar) {
        return getString(PATTERN_DEFAULT, calendar);
    }

    /**
     * Return {@link String} object from {@link Calendar} @param calendar.
     * @param pattern Pattern to use in conversion.
     * @param calendar
     * @return
     */
    public static String getString(String pattern, Calendar calendar) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(calendar.getTime());
    }
}

Related

  1. dateToString(Calendar date, DateFormat format)
  2. getDateString(Calendar cal)
  3. getDateString(Calendar cal)
  4. getDateString(Calendar calendar)
  5. getDateToString(Calendar argCal)
  6. toString(Calendar c)
  7. toString(Calendar cal)
  8. toString(Calendar cal)
  9. toString(Calendar cal)