บทความนี้แนะนำการดำเนินงานที่เกี่ยวข้องกับวันที่ในระหว่างกระบวนการพัฒนา Java
แพ็คเกจ JSE; การดำเนินการวันที่ใช้ * * * @author puck * สร้างขึ้น 2015-07-30 22:54:38 */คลาสสาธารณะ testdate {โมฆะคงที่สาธารณะหลัก (สตริง [] args) โยน parseeeexcetion, unsupport edencodingexception ); / / cal.add (calendar.day_of_month, -48); ) {// simpledateFormat format = new SimpledateFormat ("y 年 mm 月 dd 日 e hh 时 mm 分 ss 秒", locale.china); // รูปแบบ simpledateFormat = new SimpledateFormat ("y 年 m 月 d 日 eh 时 m; S "Second", Local.China); @Param Date * @return * / String สาธารณะคงที่ datetoString (ปฏิทิน cal) {ส่งคืน dateToString (cal.getTime ())); ปฏิทินคงที่ DatestringOcalendar (String Datestr) โยน Parseexception {// ปฏิทิน Caln Dar.getInstance (); Parseint (date.substring (5, 7)) -1, // integer.parseint (date.substring (8, 10))); MM: SS "); วันที่วันที่ = sdf.parse (datestr); ปฏิทิน cal = calendar.getInstance (); cal.Settime (วันที่); cal;} / ** * datestring ถึงวันที่ * * @param วันที่ * รูปแบบ: รูปแบบ: yyyy-mm-dd hh: mm: ss วันที่ * @return carer * @throws parseexception */ public static datestrowtodate (วันที่สตริง) พ่น parseexception {simpledateFormat SDF = ใหม่ SimpleDateFormat ("YYYY-MM-DD HH: MM: SS" ; ส่งคืน sdf.parse (วันที่);} / ** * วันที่แปลงเป็นปฏิทิน * * @param วันที่ * @return * / public staticar datetocalendar (วันที่) {วันที่) ; วันที่ คำนวณความแตกต่างระหว่างสองวัน ] p2 = {calendar.year [1] = " + p1 [1] +" p1 [2] = " + p1 [2]); system.out.println (" p2 [0] = " + p2 [0] +" p2 [1] = " + p2 [1] +" p2 [2] = " + p2 [2]); int ปี = p2 [0] -p1 [0]; int month = (p2 [0] * 12) + p2 [1] - (P1 [0] * 12) + P1 [1]); int [] {ปีเดือนวันวัน};}/ ** * ในวันแรกของวันที่ได้มาวันที่ได้รับ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / SimpledateFormat2 = รูปแบบใหม่ Simpledate ("Y Year Moon D D เมื่อ EH ถูกแบ่งออกเป็นวินาที", local.china); ); @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ return ** วันสุดท้ายของเดือน * @param * @param เดือน * @return * / สาธารณะคงที่ int getlastdayofmonth (int ปี, เดือน int) {ปฏิทิน c = calendar.getInstance (); 1); Calendar.day_of_month);} / *** รับวันสุดท้ายของเดือน * @param cal * @return * / สาธารณะคง