Java Date to Time getTimeOfDate(Date date)

Here you can find the source of getTimeOfDate(Date date)

Description

This method is used for getting

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String getTimeOfDate(Date date) 

Method Source Code

//package com.java2s;
/**//from  ww w.j av  a  2  s  .  c om
 * Copyright (C) 2013 Company. All Rights Reserved. 
 * 
 * This software is the proprietary information of Company . 
 * Use is subjected to license terms. 
 *
 * @since Jul 17, 2013 11:48:25 PM
 * @author SPA
    
 *
 */

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

public class Main {
    /**
     * This method is used for getting
     * 
     * @param date
     * @return
     */
    public static String getTimeOfDate(Date date) {
        Calendar calStart = new GregorianCalendar();
        calStart.setTime(date);
        String hour = String.valueOf(calStart.get(Calendar.HOUR_OF_DAY));
        String zero = "0";
        if (hour.length() < 2) {
            hour = zero.concat(hour);
        }
        String min = String.valueOf(calStart.get(Calendar.MINUTE));
        if (min.length() < 2) {
            min = zero.concat(min);
        }
        String sec = String.valueOf(calStart.get(Calendar.SECOND));
        if (sec.length() < 2) {
            sec = zero.concat(sec);
        }

        return hour.concat(min.concat(sec));
    }
}

Related

  1. getTimeIntervalMins(Date firstDate, Date lastDate)
  2. getTimeLocalWithoutDst(java.util.Date d)
  3. getTimeLocalWithoutDst(java.util.Date d)
  4. getTimeMargin(String dateTime)
  5. getTimeMax(Date date)
  6. getTimeOnly(Date date)
  7. getTimeOnly(Date date)
  8. getTimeOnly(final Date oDate)
  9. getTimePart(Date dateObject)