Here you can find the source of toSimpleDate(Calendar calendar, String format)
Parameter | Description |
---|---|
calendar | The date |
format | The format |
public static String toSimpleDate(Calendar calendar, String format)
//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; } }