get current time in hour HH format - Android java.util

Android examples for java.util:Date Format

Description

get current time in hour HH format

Demo Code

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

public class Main {

  public static int getData_HH() {
    SimpleDateFormat formatter = new SimpleDateFormat("HH");
    Date curDate = new Date(System.currentTimeMillis());
    int str = Integer.parseInt(formatter.format(curDate).toString());
    return str;/*from  w w  w .  j  a  v a 2s.  c  om*/
  }

}

Related Tutorials