Java Year Format getFirstDate(String yearMonthStr, String yearMonthFormat, String dateFormat)

Here you can find the source of getFirstDate(String yearMonthStr, String yearMonthFormat, String dateFormat)

Description

get First Date

License

Open Source License

Declaration

public static String getFirstDate(String yearMonthStr, String yearMonthFormat, String dateFormat)
            throws Exception 

Method Source Code

//package com.java2s;

import java.text.*;

public class Main {
    public static String getFirstDate(String yearMonthStr, String yearMonthFormat, String dateFormat)
            throws Exception {

        DateFormat dfYearMonth = new SimpleDateFormat(yearMonthFormat);
        DateFormat dfDate = new SimpleDateFormat(dateFormat);
        java.util.Date date;/*  w w  w.j  a  v  a2 s  . c o m*/

        if (yearMonthStr == null || yearMonthStr.equals("")) {
            throw new Exception(yearMonthStr + " is invalid.");
        }

        try {
            date = dfYearMonth.parse(yearMonthStr);
        } catch (ParseException e) {
            throw new Exception(yearMonthStr + " is invalid.");
        }

        return dfDate.format(date);
    }
}

Related

  1. formatYyyyMm(Date date)
  2. formatyyyyMMddHHmmss(long time)
  3. get_Oracle_DateString_YYYYMMdd_HHmmss(java.util.Date date)
  4. getDDMMYYY_HHMM()
  5. getDDMMYYYYDate(Date date)
  6. getFormatToDateSimple(String yyyyMMdd)
  7. getStartAndEndWeekOfMonth(int year, int month, int week, String format)
  8. getStringFormatMMYYWithoutHyphens(Date aDate)
  9. getStringFormatYYYYMMddWithHyphens(Date aDate)