Java Date to Time toTimeStr(Date date)

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

Description

to Time Str

License

Apache License

Declaration

public static String toTimeStr(Date date) 

Method Source Code

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

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static final String DEFAULT_FORMAT_TIME = "HH:mm:ss";

    public static String toTimeStr(Date date) {
        return toDateString(date, DEFAULT_FORMAT_TIME);
    }//from  ww w.  j a  v a2 s  . co  m

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

    public static String format(String text, Date date) {
        int start = text.indexOf("{");
        int end = text.indexOf("}");
        while (start > 0 && end > 0) {
            String subStr = text.substring(start, end + 1);
            String format = text.substring(start + 1, end);
            String dateStr = toDateString(date, format);
            text = text.replace(subStr, dateStr);

            start = text.indexOf("{");
            end = text.indexOf("}");
        }
        return text;
    }
}

Related

  1. toLocalDateTime(Date date)
  2. toLocalTimeString(Date d)
  3. toMT4TimeString(Date date)
  4. toSimpleDateTime(Date date)
  5. toTime(Date... date)
  6. ToTimeStr(Date dt)
  7. toTimeString(Date date)
  8. toTimeString(Date date)
  9. toTimeString(Date date)