convert Second to String - Android java.util

Android examples for java.util:Date Convert

Description

convert Second to String

Demo Code

import android.content.Context;
import android.provider.Settings;
import android.telephony.PhoneNumberUtils;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String convertSecondToString(int totalSecond) {
        String timeString = "";
        int seconds = totalSecond % 60;
        int minutes = (totalSecond / 60) % 60;
        int hours = totalSecond / 60 / 60;
        if (hours > 0) {
            timeString += hours + ":";
        }//  w w w  .  j  a  v a  2s .c o m
        if (minutes > 9) {
            timeString += minutes + ":";
        } else {
            timeString += "0" + minutes + ":";
        }
        if (seconds > 9) {
            timeString += seconds;
        } else {
            timeString += "0" + seconds;
        }

        return timeString;
    }

}

Related Tutorials