Here you can find the source of getMonth(boolean name)
Parameter | Description |
---|---|
name | if true returns the digit, otherwise returns the name of the month. |
public static String getMonth(boolean name)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005-2012 Synopsys, Incorporated * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from ww w . ja v a2 s .c om * Synopsys, Inc - Initial implementation *******************************************************************************/ import java.util.Calendar; public class Main { private static Calendar mCalendar = null; private static String[] months = new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /** * Returns either the name or the month number depending on the name parameter specified. N.B. If the month number * is returned, it will be a digit from 1-12. * @param name if true returns the digit, otherwise returns the name of the month. * @return either the name or the month number depending on the parameter specified. */ public static String getMonth(boolean name) { if (mCalendar == null) Init(); if (name) return months[mCalendar.get(Calendar.MONTH)]; else { String retVal = null; int val = mCalendar.get(Calendar.MONTH) + 1; if (val < 10) retVal = "0" + val; else retVal = val + ""; return retVal; } } /** * This method creates a new Calendar object */ public static void Init() { mCalendar = Calendar.getInstance(); } }