get Hour from date value in long - Android java.util

Android examples for java.util:Date Time

Description

get Hour from date value in long

Demo Code

import java.util.Calendar;

public class Main {

  public static String getHour(long time) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(time);/*from  ww w.j  a  v  a 2 s . c o  m*/
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    String times = "" + hour;
    if (minute < 10) {
      times += ":0" + minute;
    } else {
      times += ":" + minute;
    }
    return times;
  }

}

Related Tutorials