parse Long To Time - Android java.util

Android examples for java.util:Date Time

Description

parse Long To Time

Demo Code

import android.util.Log;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Main{

    public static String parseLongToTime(long l) {
        StringBuffer sb = new StringBuffer();
        try {//from  w  w w. j  a  v a2  s . c  o  m
            int d = (int) l / (24 * 60 * 60 * 1000);
            long rest = l % (24 * 60 * 60 * 1000);
            int h = (int) rest / (60 * 60 * 1000);
            rest = rest % (60 * 60 * 1000);
            int m = (int) rest / (60 * 1000);
            rest = rest % (60 * 1000);
            int s = (int) rest / 1000;
            rest = rest * 1000;
            sb.append(d + "d" + h + "h" + m + "m" + s + "s");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }

}

Related Tutorials