Android Date Format toTimeString(Date value)

Here you can find the source of toTimeString(Date value)

Description

to Time String

License

Apache License

Declaration

public static String toTimeString(Date value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static String toTimeString(Date value) {
        if (value != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

            return dateFormat.format(value);
        } else {/*from w w  w .  j a va  2  s  .co  m*/
            return "";
        }
    }

    public static String toTimeString(long milliseconds) {
        long secs = milliseconds / 1000;
        long mins = secs / 60;
        long hours = mins / 60;

        secs = secs % 60;
        mins = mins % 60;

        if (hours > 0) {
            return String.format("%d:%02d:%02d", hours, mins, secs);
        }

        return String.format("%d:%02d", mins, secs);
    }
}

Related

  1. toRelativeDateString(Date value)
  2. toString(Date date, String format)
  3. toString(Date value, String format)
  4. toStringFR(Date date)
  5. toStringUS(Date date)
  6. format(Date date)
  7. format(Date date, String pattern)
  8. formatData(Date date)
  9. formatDate(final Date date)