Obtains the first day of the specified month and the last day of the specified month.
/**
* Obtain the first day of the specified month.
*
* @ Param strdate string
* @ Return string
*/
Public String getmonthbegin (string strdate)
{
Java. util. Date = parseformatdate (strdate );
Return formatdatebyformat (date, "yyyy-mm") + "-01 ";
}
/**
* Get the last day of the specified month
*
* @ Param strdate string
* @ Return string
*/
Public String getmonthend (string strdate)
{
Java. util. Date = parseformatdate (getmonthbegin (strdate ));
Calendar calendar = calendar. getinstance ();
Calendar. settime (date );
Calendar. Add (calendar. month, 1 );
Calendar. Add (calendar. day_of_year,-1 );
Return formatdate (calendar. gettime ());
}
/**
* Common formatting dates
*
* @ Param date
* @ Return string
*/
Public String formatdate (Java. util. Date)
{
Return formatdatebyformat (date, "yyyy-mm-dd ");
}
/**
* Format the date in the specified format.
*
* @ Param date
* @ Param Format String
* @ Return string
*/
Public String formatdatebyformat (Java. util. Date, string format)
{
String result = "";
If (date! = NULL)
{
Try
{
Simpledateformat SDF = new simpledateformat (format );
Result = SDF. Format (date );
}
Catch (exception ex)
{
Logger.info ("Date:" + date );
Ex. printstacktrace ();
}
}
Return result;
}