Android Calendar Format toSimpleDate(Calendar calendar, String format)

Here you can find the source of toSimpleDate(Calendar calendar, String format)

Description

Format a calendar date to a string with a certain format.

License

MIT License

Parameter

Parameter Description
calendar The date
format The format

Return

A formatted string according to 'format'

Declaration

public static String toSimpleDate(Calendar calendar, String format) 

Method Source Code

//package com.java2s;
/**/* w w  w  .  j  a v a 2  s  .c om*/
 *   DateTimeUtils.java
 *
 *  A utility class for converting dates to common formats
 *
 *   @author Robin Andersson, Johan Brook
 *   @copyright (c) 2012 Robin Andersson, Johan Brook, Mattias Henriksson, Lisa Stenberg
 *   @license MIT
 */

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

public class Main {
    /**
     * Recieves a calendar instance and returns a String with simple date format
     * ("d MMM, yyyy" = "14 Oct, 2012")
     * 
     * @param calendar
     *            The calendar object to be used to create the string
     * @returns A simple string representing a date in the format: "d MMM, yyyy"
     */
    public static String toSimpleDate(Calendar calendar) {
        return toSimpleDate(calendar, "d MMM, yyyy");
    }

    /**
     * Format a calendar date to a string with a certain format.
     * 
     * @param calendar
     *            The date
     * @param format
     *            The format
     * @return A formatted string according to 'format'
     * @see SimpleDateFormat
     */
    public static String toSimpleDate(Calendar calendar, String format) {
        SimpleDateFormat simpleDate = new SimpleDateFormat(format);
        String simpleDateString = simpleDate.format(calendar.getTime());

        return simpleDateString;
    }
}

Related

  1. calendar2string(Calendar calendar, String formatString)
  2. format(Calendar cal, String format, Locale locale)
  3. getCalendarFromDateString(String dateString, String format, Locale locale)
  4. getFormatedDate(Calendar c, String format)
  5. string2calendar(String s, String formatString)
  6. getCurrentDateString(String dateFormat)
  7. getAsString(Calendar date)
  8. formatCalendar(Calendar calendar)
  9. formatCalendar(Calendar calendar, String pattern)