Android Calendar to String Convert toSimpleDate(Calendar calendar)

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

Description

Recieves a calendar instance and returns a String with simple date format ("d MMM, yyyy" = "14 Oct, 2012")

License

MIT License

Parameter

Parameter Description
calendar The calendar object to be used to create the string

Declaration

public static String toSimpleDate(Calendar calendar) 

Method Source Code

//package com.java2s;
/**//ww w .j  ava2s .c  o m
 *   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. convertToDateStamp(Calendar cal)
  2. toHumanDate(Calendar cal)
  3. calendarToString(Calendar date)