오늘로 부터 내가 원하는 날짜가 얼마 남았는지 확인해보는 함수입니다.


// 기념일 계산
    public double dayCount(String date) throws ParseException
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date goal = sdf.parse(date);
        Date today = new Date();
        double dayLeft = (double)(goal.getTime()-today.getTime())/1000/(24*60*60);
        // 2자리 반올림
        return (double)Math.round(dayLeft*100)/100;
    }
    
    public double dayCount(int year, int month, int day) throws ParseException
    {
        return dayCount(year+"-"+month+"-"+day);
    }


오늘부터 1월 1일까지 남은시간은 82.36일 이네요



+ Recent posts