Java Date to Time getTimeString(Date date)

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

Description

HHmmss

License

Open Source License

Parameter

Parameter Description
date a parameter

Declaration

public static String getTimeString(Date date) 

Method Source Code


//package com.java2s;
import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public final static String timeFormat = "HHmmss";

    /**/*  w w w . j ava2s.co m*/
     * HHmmss
     * 
     * @param date
     * @return
     */
    public static String getTimeString(Date date) {
        DateFormat dateFormat = createNewDateFormat(timeFormat);
        return formatDateString(date, dateFormat);
    }

    public static DateFormat createNewDateFormat(String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        df.setLenient(false);
        return df;
    }

    public static String formatDateString(Date date, DateFormat dateFormat) {
        if (date == null || dateFormat == null) {
            return null;
        }
        return dateFormat.format(date);
    }

    public static String format(Date date, String format) {
        if (date == null) {
            return null;
        }
        return new SimpleDateFormat(format).format(date);
    }
}

Related

  1. getTimeStampInMin(Date date)
  2. getTimeStampInSec(char separator, Date date)
  3. getTimestampl(Date time1, Date time2)
  4. getTimeStr(Date date, char delimiter)
  5. getTimeString(Date d)
  6. getTimeString(Date self)
  7. getTimeString(java.util.Date date)
  8. getTimeText(Date date)
  9. getXSDDateTime()