安卓时间戳转天时分秒

方法如下,其中times_remain为时间戳
private void updateTextView(Long times_remain) {

    int day = 0;
    int hour = 0;
    int minute = 0;
    int second = 0;
    second = times_remain.intValue();
    if (second > 60) {
        minute = second / 60;         //取整
        second = second % 60;         //取余
    }

    if (minute > 60) {
        hour = minute / 60;
        minute = minute % 60;
    }

    if (hour > 60) {
        day = hour / 24;
        hour = hour % 24;
    }
    String secondFormat = second < 10 ?  "0" + String.valueOf(second) : "" + second;
    String minuteFormat = minute < 10 ?  "0" + String.valueOf(minute) : "" + minute;
    String hourFormat = hour < 10 ?  "0" + String.valueOf(hour) : "" + hour;
    String dayFormat = hour < 10 ?  "0" + String.valueOf(day) : "" + day;
}

你可能感兴趣的:(安卓时间戳转天时分秒)