Java SQL Time Field getHour(String time)

Here you can find the source of getHour(String time)

Description

get Hour

License

Open Source License

Declaration

public static String getHour(String time) 

Method Source Code

//package com.java2s;

import java.text.*;

public class Main {
    public static SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

    public static String getHour(java.sql.Date date) {
        return timeFormat.format(date).substring(0, 2);
    }/*from ww  w .  ja  va2  s.co m*/

    public static String getHour(String time) {
        int hour = Integer.parseInt(time.substring(0, 2));
        String ret_hour = null;

        if (hour > 12) {
            if (hour < 10)
                ret_hour = "0" + Integer.toString(hour - 12);
            else
                ret_hour = Integer.toString(hour - 12);
        } else {
            if (hour < 10)
                ret_hour = "0" + Integer.toString(hour);
            else
                ret_hour = time.substring(0, 2);
        }

        return ret_hour;
    }
}

Related

  1. clearTimeCommon(final Calendar self)
  2. clearTimeFields(java.sql.Date date)
  3. clearTimeFields(java.util.Date date)
  4. getDay(long time)
  5. getHoraFormatada(Time hora, String formato)
  6. getHoursAndMinutes(String dateTime)
  7. getSecond(Time time)