Here you can find the source of getNowHour()
public static String getNowHour() throws Exception
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.*; public class Main { static SimpleDateFormat sdfLongTimePlusMill = new SimpleDateFormat("yyyyMMddHHmmssSSSS"); public static String getNowHour() throws Exception { String nowHour = ""; try {//from w ww . java2 s .c o m String strTemp = getNowPlusTimeMill(); nowHour = strTemp.substring(8, 10); return nowHour; } catch (Exception e) { throw e; } } public static String getNowPlusTimeMill() throws Exception { String nowDate = ""; try { java.sql.Date date = null; date = new java.sql.Date(new Date().getTime()); nowDate = sdfLongTimePlusMill.format(date); return nowDate; } catch (Exception e) { throw e; } } /** * Returns a string the represents the passed-in date parsed * according to the passed-in format. Returns an empty string * if the date or the format is null. **/ public static String format(Date aDate, SimpleDateFormat aFormat) { if (aDate == null || aFormat == null) { return ""; } synchronized (aFormat) { return aFormat.format(aDate); } } }