Here you can find the source of toYearMonth(String dateString)
public static Date toYearMonth(String dateString)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import com.google.common.base.Strings; public class Main { private static final SimpleDateFormat YEAR_MONTH_FORMAT = new SimpleDateFormat("yyyy-MM"); public static Date toYearMonth(String dateString) { if (Strings.isNullOrEmpty(dateString)) { return null; }/*from ww w . jav a 2s . com*/ try { return YEAR_MONTH_FORMAT.parse(dateString); } catch (ParseException e) { throw new RuntimeException(e); } } }