Here you can find the source of toString(Calendar calendar)
Parameter | Description |
---|---|
calendar | calendar |
public static String toString(Calendar calendar)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { public static final DateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat("EEE, MM/dd/yyyy, hh:mm:ss a, z"); /**//from w w w . j a v a2 s . c om * Default calendar to string conversion. * * @param calendar calendar * @return string representation */ public static String toString(Calendar calendar) { return toString(calendar, DEFAULT_DATE_FORMAT); } /** * Convert date and time zone to a default string representation. * * @param date date * @param zone time zone * @return string representation */ public static String toString(Date date, TimeZone zone) { return toString(date, zone, DEFAULT_DATE_FORMAT); } /** * Convert date and time zone to a specified string representation. * * @param date date * @param zone time zone * @param formatter specified format * @return string representation */ public static String toString(Date date, TimeZone zone, DateFormat formatter) { if (date == null) { return null; } Calendar c = new GregorianCalendar(); c.setTime(date); if (zone != null) { c.setTimeZone(zone); } return toString(c, formatter); } /** * Convert calendar to a string representation. * * @param calendar calendar * @param formatter formatter * @return string representation */ public static synchronized String toString(Calendar calendar, DateFormat formatter) { formatter.setCalendar(calendar); return formatter.format(calendar.getTime()); } }