Here you can find the source of getYear(String date)
public static int getYear(String date)
//package com.java2s; import java.util.*; public class Main { public static int getYear(String date) { date = deleteSlash(date);/*from ww w .j ava 2 s .co m*/ date = deleteDash(date); return Integer.parseInt(date.substring(0, 4)); } public static String deleteSlash(String value) { return deleteChar(value, "/"); } public static String deleteDash(String value) { return deleteChar(value, "-"); } public static String deleteChar(String source, String deleteStr) { if (source == null || "".equals(source.trim())) { return ""; } StringBuffer temp = new StringBuffer(""); StringTokenizer st = new StringTokenizer(source, deleteStr); while (st.hasMoreTokens()) { temp.append(st.nextToken()); } return temp.toString(); } }