Package cn.com. eatlab. report. util; import Java. util. calendar; import Java. util. date; public class dateutils {/*** get the start and end dates of a month * @ Param monthnum 0 this month-1, last month, and so on * @ return */@ suppresswarnings ("deprecation") public static date [] getdatefirstdayandlastday (integer monthnum) {calendar calendar1 = calendar. getinstance (); int month = calendar1.get (calendar. month); // the current month monthnum =-1,-2... 2013-04-24 11: 30: 16system. out. println ("current month: Calendar. month: "+ month); calendar1.set (calendar. month, month + monthnum); // 2013-02-24 11:30:16 // get the last day of the month calendar ar1.set (calendar. month, calendar1.get (calendar. month) + 1); calendar1.set (calendar. date, 1); calendar1.add (calendar. date,-1); // int lastday = calendar1.get (calendar. date); calendar1.set (calendar. month, month + monthnum); calendar1.set (calendar. date, 1); calendar1.set (calendar. hour_of_day, 0); calendar1.set (calendar. minute, 0); calendar1.set (calendar. second, 0); Date date1 = calendar1.gettime (); calendar1.set (calendar. date, lastday); calendar1.set (calendar. hour_of_day, 23); calendar1.set (calendar. minute, 59); calendar1.set (calendar. second, 59); Date date2 = calendar1.gettime (); date [] Dates = new date [2]; dates [0] = date1; dates [1] = date2; return dates;}/*** get the number of days of the previous premonthnum month. 0 indicates this month, -1 last month * @ Param premonthnum * @ return */public static integer getdaynumofmonth (integer premonthnum) {calendar calendar1 = calendar. getinstance (); int month = calendar1.get (calendar. month); calendar1.set (calendar. month, month + premonthnum); calendar1.set (calendar. month, calendar1.get (calendar. month) + 1); calendar1.set (calendar. date, 1); calendar1.add (calendar. date,-1); // int lastday = calendar1.get (calendar. date); Return lastday;} public static string dateformat (Java. util. date) {// Java. text. simpledateformat SDF = new Java. text. simpledateformat ("yyyy/mm/dd hh: mm: SS"); // string C1 = SDF. format (date); // system. out. println ("Full Time Format:" + date. tolocalestring (); string temptimestr = ""; // obtain the year, month, and day of the time to be compared. Int tempdate = date. getdate (); int tempmonth = date. getmonth () + 1; int tempyear = date. getyear () + 1900; // system. out. println (tempdate + "" + tempmonth + "" + tempyear); // obtain the year, month, and day of the current time. getinstance (); // system. out. println ("now:" + now. tostring (); // system. out. println ("Date:" + now. get (calendar. date) + "-month:" + now. get (calendar. month) + "-year:" + now. get (calendar. year); int nowdate = now. get (calendar. date); int nowmonth = now. get (calendar. month) + 1; int nowyear = now. get (calendar. year); If (nowyear> tempyear) {// last year Java. text. simpledateformat SDF = new Java. text. simpledateformat ("yyyy/mm/DD"); temptimestr = SDF. format (date);} else if (nowmonth-tempmonth> = 1) {// Java. text. simpledateformat SDF = new Java. text. simpledateformat ("yyyy/mm/DD"); temptimestr = SDF. format (date);} else if (nowdate-tempdate> = 2) {// the day before yesterday or this month Java. text. simpledateformat SDF = new Java. text. simpledateformat ("mm/DD"); temptimestr = SDF. format (date);} else if (nowdate-tempdate = 1) {// Java yesterday. text. simpledateformat SDF = new Java. text. simpledateformat ("HH: mm"); temptimestr = "yesterday";} else {// Today Java. text. simpledateformat SDF = new Java. text. simpledateformat ("HH: mm"); temptimestr = SDF. format (date) ;}return temptimestr ;}}