Convert long data To String HH:MM - Android java.util

Android examples for java.util:Date Time

Description

Convert long data To String HH:MM

Demo Code

import android.text.TextUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String dataToString24HM(long time) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(time);/*from w ww  .  j a v  a 2s.c o m*/
        int h = cal.get(Calendar.HOUR_OF_DAY);
        int m = cal.get(Calendar.MINUTE);
        String hs = h < 10 ? "0" + h : "" + h;
        String ms = m < 10 ? "0" + m : "" + m;
        return hs + ":" + ms;
    }

}

Related Tutorials