get Time Description for seconds - Android java.util

Android examples for java.util:Date Time

Description

get Time Description for seconds

Demo Code

import android.text.TextUtils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main{

    public static String getTimeDescription(long milliseconds) {
        if (milliseconds > 1000) {
            if (milliseconds / 1000 / 60 > 1) {
                long minute = milliseconds / 1000 / 60;
                long second = milliseconds / 1000 % 60;
                return minute + "minute" + second + "second";
            } else {
                return milliseconds / 1000 + "second";
            }// ww w  . jav  a  2 s. c  o m
        } else {
            return milliseconds + "millisecond";
        }
    }

}

Related Tutorials