Java examples for java.util:Month
Gets day, month and year out of the calendar and converts it into a String.
import java.util.Calendar; public class Main{ public static void main(String[] argv) throws Exception{ Calendar calendar = Calendar.getInstance(); System.out.println(getCalendaDateAsString(calendar)); }/*from w w w .j a v a2 s. co m*/ /** * Gets day, month and year out of the calendar and converts it into a String. * @param calendar object, where you want the date from. * @return String of the date. */ public static String getCalendaDateAsString(Calendar calendar) { return calendar.get(Calendar.DAY_OF_MONTH) + ". " + CalendarHelper.getMonthAsString(calendar .get(Calendar.MONTH)) + " " + calendar.get(Calendar.YEAR); } /** * Returns the Month string for a month number. * @param month Integer wich represents a month. * @return String of the month. */ public static String getMonthAsString(int month) { String[] monthNames = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; return monthNames[month]; } }