이 기사는 Java 개발 프로세스 중에 날짜 관련 작업을 소개합니다.
JSE; import java.text.simpledateformat; 사용 된 날짜 조작 * * * @author puck * 생성 된 2015-07-30 22:54:38 */public class testdate {public static void main (string [] args)은 parseeeexcetion, Unsupport edencodingException {Calendar cal = calendar.getinstance를 던졌습니다. ); / / cal.add (calendar.day_of_month, -48);}; ) {// simpledateformat 형식 = new SimpledateFormat ( "y 年 mm 月 dd 日 e hh 时 mm 分 ss 秒", locale.china); // simplededateformat = new SimpledateFormat ( "y 年 m 月 d 日 eh 时 m 分 m 分s "sec @param 날짜 * @return * / public static string dateToString (Calendar Cal) {return dateToString (cal.gettime ())); 정적 캘린더 Datestringocalendar (String DateStres)는 parseexception {// caln dar.getinstance (); parseint (date.substring (5, 7)) -1, // integer.parseint (date.substring (8, 10)); mm : ss "); 날짜 date = sdf.parse (datest); calendar cal = calendar.getInstance (); cal.settime (date); cal;} / ** * datestring to date * * @param date * format : yyyy-mm-dd hh : mm : ss date * @return carer * @throws parseexception */ public static datestrowtodate (문자열 날짜) parseeexception {simplededateformat sdf = new simpledateformat ( "yyyy-mm-dd hh : mm : ss"). return sdf.parse (날짜);} / ** * 날짜 캘린더로 변환 * @param 날짜 * / public staticar dateTocalendar (날짜) {calendar c1 = calendar.getInstance (); ); return c1;} / ** * 캘린더 날짜로 변환 날짜. 두 날짜를 계산합니다. 1. 캘린더 C2) {int [] p1 = {calendar.year), c1.get, c1.get (calendar.day_of_month)}; ] p2 = {calendar.year), c2. get (calendar.month), system.out.println; [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 [] {연도, 월, 일};}/ ** * 획득 날짜의 첫날 * * * * * @param c * @return */ public static calendar getlastdayofweek (calendar c) {/ / simpledateformat2 = 새로운 단순화 형식 (y year moon d d eh가 s 초로 나뉩니다. // system.out.println; 월요일 월요일); // system.out.println ( "월요일 시간 :" + format2.format (c.gettime ());} * 날짜 * @param c * @param day * @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ calendar c, int day) {calendar.day_of_month, day); ** 달의 마지막 날 * @param * @param month * @return * / public static int getlastdayofmonth (int 연도, int month) {calendar c = calendar.getInstance (); 1); 캘린더 day_of_month);} / *** 달의 마지막 날 * @param cal * @return * / public static int getlastdayofmonth (Calendar Cal) {return cal.getactualmaxumum (calendar.day_month);}}