Java SQL Date getNowHour()

Here you can find the source of getNowHour()

Description

get Now Hour

License

Apache License

Declaration

public static String getNowHour() throws Exception 

Method Source Code

//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);
        }
    }
}

Related

  1. getMonthInt(String month)
  2. getNextDayStr(String curday)
  3. getNextDayStr(String curday)
  4. getNow()
  5. getNow()
  6. getProtobufClass(Object value, Class protobufClass)
  7. getTodayAndTomorrow()
  8. getWeekNumber()
  9. getWeekOfMonth(String year, String month, String day)