본문 바로가기

Study/Android

[Android] 현재시간에서 특정날짜 까지의 차이 구하기

현재시간에서 특정날짜 까지의 차이 구하기

private long second = 1000;
private long min = 60 * second;
private long hour = 60 * min;
private long day = 24 * hour;

public void getCurrent() {
	Calendar currentCal = Calendar.getInstance();
	Calendar targetCal = Calendar.getInstance();
    targetCal.set(Calendar.DAY_OF_WEEK, 7);
    targetCal.set(Calendar.HOUR_OF_DAY, 20);
    targetCal.set(Calendar.MINUTE, 00);
    targetCal.set(Calendar.SECOND, 00);

    long what = targetCal.getTimeInMillis() - currentCal.getTimeInMillis();
    long day = what / this.day;
        
    StringBuffer sb = new StringBuffer();
    sb.append(day + "일");
    sb.append( ((what % this.day)/this.hour) + "시간");
    sb.append( (((what % this.day)/this.hour)/this.min) + "분");
    sb.append( ((((what % this.day)/this.hour)/this.min)/this.second) + "초");
}

출처 : http://al02000.tistory.com/33

 

 

 

custom calendar view

설명

https://www.toptal.com/android/android-customization-how-to-build-a-ui-component-that-does-what-you-want

 

소스

https://github.com/ahmed-alamir/CalendarView