Here you can find the source of getTimeString(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static String getTimeString(Date date)
//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); } }