Package Pbcenter.util;
Import java.util.calendar; import java.sql.date; import java.text.SIMPLEDATEFORMAT; import java.text.parsexception;
/ ** * uTility to date time * @version 0.1 * @Author super zhao * / public class datetimeutil {/ ** * is converted by java.util.date to java.sql.date Type conversion * @Param Date * @Return Date * / Public static date getsqldate (java.util.date date) {return new date ());} public static dateowdate () {Calendar Calendar = Calendar.GetInstance (); returnşngettime (Calendar.gettime ));} / ** * After a certain day, the day * @Param Date * @return Date * / public static date getnextdate (Date Date) {Calendar Calendar = Calendar.GetInstance (); Calendar.SetTime (Date); INT days = calendar.get (Calendar.date); Calendar.date (Calendar.date, Day 1); return getsqldate (Calendar.gettime ());} / ** * Get a day before * @Param Date * @Return Date * / public static date getPreviousDate (Date Date) {Calendar Calendar = Calendar.GetInstance (); Calendar.SetTime (Date); int day = calendar.get (Calendar.date); Calendar.Set (Calendar. Date, day-1); return getsqldate (Calendar.gettime ());} / ** * Get the day of the first day of a month * @Param Year * @Param Month * @ret URN DATE * / PUBLIC Static Date GetFirstdayOfmonth (int year, int month) {Calendar Calendar = calendar.getInstance (); Calendar.Year, Year); Calendar.Month (Calendar.Mont, Month-1); Calendar .set (Calendar.Date, 1); returnşngettime ());} / ** * Get the date of the last day of a month * @Param Year * @Param Month * @return Date * / Public Static Date getlastdayofmonth (int year, int month) {Calendar Calendar = Calendar.GetInstance (); Calendar.Set (Calendar.Year, Year); Calendar.Month, Month; Calendar.date, 1 ); Return getpreviousdate (getSqldate (Calendar.gettime ()));} / ** * Build java.sql.date type * @Param year * @ @@@
PARAM MONTH * @Param Date * @Return Date * / public static date builddate (int year, int month, int Date) {Calendar Calendar = Calendar.GetInstance (); Calendar.Set (Year, Month-1, Date); Return GetSqldate (Calendar.getTime ());} / ** * gets the number of days of the month * @Param Year * @Param Month * @return int * / public static int getDaycountofmonth (int year, int month) {Calendar Calendar = Calendar. GetInstance (); Calendar.Year, Year); Calendar.Set (Calendar.Month, Month); Calendar.d (Calendar.date, 0); Return Calendar.Get (Calendar.date);} / * * * Date of the last day of a certain quarter * @Param Year * @Param quarter * @return Date * / public static date getlastdayOfquarter (int year, int quarter) {INT MONTH = 0; if (quarter> 4) { Return null;} else {month = quarter * 3;} return getlastday;} / ** * Get the day of the first day of a certain quarter * @Param Year * @Param quarter * @return Date * / Public static date getfirstdayofquarter (int year, int quarter) {INT MONTH = 0; if (quarter> 4) {return null;} else {month = (quarter -1) * 3 1;} Return getFirstdayofmonth (Year, Month);} / ** * Get a day of the first day of a year * @Param Year * @return Date * / public static date getFirstdayofyear (int year) { Return getfirstdayofmonth (Year, 1);} / ** * Get a day of the last day * @Param Year * @return Date * / public static date getlastdayofyear (int year) {Return getLastDayofmonth (Year, 12);} / ** * string to java.sql.date Type conversion * @Param param * @return Date * / public static java.sql.date stringtodate (String param) {if (Stringutil.NullBlank (param)) {Return null;} Else {java.util.date date = null; try {simpledateformat sdf = new SimpleDateFormat ("YYYY-MM-DD");