'SimpleDateFormat'에 해당되는 글 2건

  1. 2010.03.10 String으로 날짜 받아서 일자 더하기.
2010. 3. 10. 14:58

String으로 날짜 받아서 일자 더하기.

String으로 된 날짜에 일자를 더해서 세팅.

 package com.blue.controller;

 

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.*;

 

public class CalendarEx2 {

 

       public static void main(String[] arg) {

 

             // 2009.12.31 + 2

                          DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

             Date date = null;

             try {

                    date = dateFormat.parse("20091231");

             } catch (ParseException e) {

                    // TODO Auto-generated catch block

                    e.printStackTrace();

             }

             Calendar cal = Calendar.getInstance();

             cal.setTime(date);

             cal.add(Calendar.DATE, 2);

             System.out.println(date);

             System.out.println(cal.getTime());

            

             String strDate = dateFormat.format(cal.getTime());

             System.out.println(strDate);

 

       }

 

}

Trackback 0 Comment 0