Android examples for java.util:Date Format
get current time in hour HH format
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*/ } }