Java Date to String dateToTimeString(Date date)

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

Description

return time value only of specified date in format: HH:mm:ss

License

Apache License

Parameter

Parameter Description
date the specified date to convert

Return

String value

Declaration

public static String dateToTimeString(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /**//  w  w w  .  ja  v  a  2 s. c o  m
     * return time value only of specified date in format: HH:mm:ss
     *
     * @param date the specified date to convert
     * @return String value
     */
    public static String dateToTimeString(Date date) {
        return dateToStringWithPattern(date, "HH:mm:ss");
    }

    /**
     * return time value of specified date
     *
     * @param date    the specified date to convert
     * @param pattern time format
     * @return String value
     */
    public static String dateToStringWithPattern(Date date, String pattern) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
            return simpleDateFormat.format(date);
        } catch (Exception e) {
            return "";
        }
    }
}

Related

  1. dateToStringVerbose(Date date)
  2. dateToStringWithFormat(Date dateToString, String dateFormat)
  3. dateToStringWithPattern(Date date, String pattern)
  4. dateToStringWithPattern(Date date, String pattern)
  5. dateToStringWithTime(Date date)
  6. dateToUTCDate(Date d)
  7. dateToUtcString(Date date)
  8. dateToW3c(Date d)
  9. dateToW3CDTF(Date date)