Here you can find the source of getYearMonth(String dateString)
public static Date getYearMonth(String dateString)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static Date getYearMonth(String dateString) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); Date date;// w w w. j av a 2 s .c o m try { date = sdf.parse(dateString); } catch (ParseException e) { e.printStackTrace(); return null; } return date; } }