Here you can find the source of getHour()
public static String getHour()
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.*; public class Main { public static String getHour() { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(currentTime); String hour;// ww w. j a v a 2s .co m hour = dateString.substring(11, 13); return hour; } }