Contents

Views 13016 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
date.set(y,m,d...);
이런 방법이 없어짐 ㅠㅠ

두 날짜의 차이를 얻고 싶으시면, 그렇게 문자열에서 부분만을 뽑아서 계산하는 것보다는 Date 클래스를 이용하는 것이 더 깔끔하고 바람직한 방법입니다. 

다음 코드를 참고하세요.
코드를 보시면 충분히 이해하실 것이라 생각됩니다. 수행하면 결과값이 5가 나옵니다. 

SimpleDateFormat는 지정한 형태로 들어온 문자열을 Date 객체로 바꿔주는 역할을 합니다.
그리고, 이렇게 바뀌어진 두 날짜의 차이를 millisecond 단위로 구하고 이것을 다시 일단위로 바꾸는 것이지요.
import java.text.SimpleDateFormat;
import java.util.Date; 

public class DiffOfDate
{
  public static void main(String[] args) throws Exception
  {
    System.out.println(diffOfDate("20031028", "20031102"));
  }

  public static long diffOfDate(String begin, String end) throws Exception
  {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");

    Date beginDate = formatter.parse(begin);
    Date endDate = formatter.parse(end);

    long diff = endDate.getTime() - beginDate.getTime();
    long diffDays = diff / (24 * 60 * 60 * 1000);

    return diffDays;
  }
}


?

  1. [linux] 스케쥴링 순서(nice) 변경하기

    Date2003.04.23 CategorySystem/OS Byhooni Views13372
    Read More
  2. [c] 네트워크 트래릭 모니터링.. 졸업작품..

    Date2013.04.23 CategoryDevelop Byhooni Views13348
    Read More
  3. [c++] 기초강좌 #03(함수의 매개변수 전달)

    Date2003.04.23 CategoryDevelop Byhooni Views13339
    Read More
  4. [sql] alter table 쿼리 예제

    Date2003.04.23 CategorySystem/OS Byhooni Views13312
    Read More
  5. [linux] 파일내 문자열 찾아 바꾸기

    Date2013.04.23 CategorySystem/OS Byhooni Views13296
    Read More
  6. [mac] Charlesproxy 간단한 설정 내용~

    Date2013.11.12 CategorySystem/OS Byhooni Views13262
    Read More
  7. [linux] 간단한 NAT 설정 script

    Date2003.04.23 CategorySystem/OS Byhooni Views13258
    Read More
  8. [linux] 데스크탑환경(GNOME/KDE) 바꾸기..

    Date2003.04.23 CategorySystem/OS Byhooni Views13254
    Read More
  9. Mac OS 에 Jenkins 설치하기 (Homebrew)

    Date2017.03.15 CategoryDevelop Byhooni Views13246
    Read More
  10. [linux] DNS(Domain Name System) 설치, 설정

    Date2003.04.23 CategorySystem/OS Byhooni Views13236
    Read More
  11. [linux] 쉘 스크립트 (Shell Script)

    Date2003.04.23 CategorySystem/OS Byhooni Views13199
    Read More
  12. [linux] root도 삭제하지 못하는 파일 속성

    Date2003.04.23 CategorySystem/OS Byhooni Views13167
    Read More
Board Pagination Prev 1 ... 29 30 31 32 33 34 35 36 37 38 ... 99 Next
/ 99