Java Month Get getMonthBegin(String strdate)

Here you can find the source of getMonthBegin(String strdate)

Description

get Month Begin

License

Open Source License

Parameter

Parameter Description
strdate a parameter

Declaration

public static String getMonthBegin(String strdate) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static String getMonthBegin(String strdate) {
        java.util.Date date = parseDate(strdate);
        return format(date, "yyyy-MM") + "-01";
    }//from w  ww  .j  a va2  s  . com

    public static java.util.Date parseDate(String dateStr, String format) {

        java.util.Date date = null;
        try {
            java.text.DateFormat df = new java.text.SimpleDateFormat(format);
            date = (java.util.Date) df.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    public static java.util.Date parseDate(String dateStr) {
        return parseDate(dateStr, "yyyy-MM-dd");
    }

    public static String format(java.util.Date date, String format) {
        String result = "";
        try {
            if (date != null) {
                java.text.DateFormat df = new java.text.SimpleDateFormat(format);
                result = df.format(date);
            }
        } catch (Exception e) {
        }
        return result;
    }
}

Related

  1. getMonth(String tempdat, Locale locale)
  2. getMonth1D()
  3. getMonthAdd(String operateDate, int flag)
  4. getMonthAndDate()
  5. getMonthBefore(Date d, int number)
  6. getMonthBegin(String strdate)
  7. getMonthByNow(int month)
  8. getMonthCount(String from, String to)
  9. getMonthDesc(Date month)