Java Date to Time getTimeOnly(final Date oDate)

Here you can find the source of getTimeOnly(final Date oDate)

Description

get Time Only

License

Open Source License

Declaration

public static Date getTimeOnly(final Date oDate) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static final long HOUR = 60 * 60 * 1000;
    public static final long MINUTE = 60 * 1000;
    public static final long SECOND = 1000L;

    public static Date getTimeOnly(final Date oDate) {
        if (null == oDate) {
            return null;
        }//from  w  w w  .ja v a2s  . c om
        final Calendar c = Calendar.getInstance();
        c.setTime(oDate);
        c.set(Calendar.YEAR, 1970);
        c.set(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, 1);
        return c.getTime();
    }

    public static String getTime(final long time) {
        if (time <= 0) {
            return "";
        }
        if (time < SECOND) {
            return time + "ms";
        } else if (time < MINUTE) {
            return (time / SECOND) + "s" + getTime(time % SECOND);
        } else if (time < HOUR) {
            return (time / MINUTE) + "m" + getTime(time % MINUTE);
        } else if (time >= HOUR) {
            return (time / HOUR) + "h" + getTime(time % HOUR);
        }
        return "";
    }
}

Related

  1. getTimeMargin(String dateTime)
  2. getTimeMax(Date date)
  3. getTimeOfDate(Date date)
  4. getTimeOnly(Date date)
  5. getTimeOnly(Date date)
  6. getTimePart(Date dateObject)
  7. getTimePeriod(Date date)
  8. getTimerDate(String time)
  9. getTimeRoll(Date current, int field, int numberOfRoll)