프로그래밍 언어 /java
날짜에 관하여...형식지정 날짜비교..
dreammarker
2019. 2. 1. 11:47
java에서 날짜 형식 타입을 지정하는 방법
날짜를 비교하거나 시간을 비교할때
SimpleDateFormat 을 사용해서 format형식을 먼저 정한다.
날짜
SimpleDateFormat dtformat = new SimpleDateFormat("yyyy-MM-dd");
시간
SimpleDateFormat tmFormat = new SimpleDateFormat("HH:mm");
Date dayonDe = format.parse(x); //x는 비교할 날짜 시간
Date dayoffDe = format.parse(y); //y도 비교할 날짜 시간
Format에 dtformat을 넣으면 날짜비교가 가능하며
tmFormat을 넣으면 시간 비교가 가능하다.
그 다음 compareTo함수를 이용해서
int compare=dayonDe.compareTo(dayoffDe);
두개의 날짜나 시간을 비교한다
-1 0 1의 값이 나온다
값이 비교했을때 크면 1
같으면 0
작으면 -1 이다.
밑에 는 날짜 표현 방식이다.
SimpleDateFormat 날짜 방식..