Here you can find the source of month(String monthName)
Parameter | Description |
---|---|
monthName | The name of the month, in English |
public static int month(String monthName)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w. ja va 2 s . c o m*/ * The names of the months */ private static final String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; /** * Convert a month name (english names) (or a valid abbreviation) to an int in {1,12}. * Warning: the current implementation uses startsWith(), so month("J") returns 1. * * @param monthName The name of the month, in English * @return the month number, in the range 1-12. */ public static int month(String monthName) { for (int i = 0; i < months.length; i++) { String m = months[i]; if (m.startsWith(monthName)) { return i + 1; } } return -1; } }