Java Hour Format formatTime(Date date)

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

Description

format Time

License

Open Source License

Return

time value in format HH:mm

Declaration

public static String formatTime(Date date) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

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

public class Main {
    private static SimpleDateFormat timeDF = // getDateShortFormat
            new SimpleDateFormat("HH:mm", Locale.getDefault());
    private static String NOT_DEFINED_DATE = "-";

    /**/* ww  w . j a  v a  2 s  .  com*/
     * @return time value in format HH:mm
     */
    public static String formatTime(Date date) {
        if (date == null) {
            return NOT_DEFINED_DATE;
        }
        return timeDF.format(date.getTime());
    }

    public static String getTime(Date time, int format, Locale locale) {
        return SimpleDateFormat.getTimeInstance(format, locale).format(time);
    }
}

Related

  1. formatTime(Date d)
  2. formatTime(Date d)
  3. formatTime(Date date)
  4. formatTime(Date date)
  5. formatTime(Date date)
  6. formatTime(Date date)
  7. formatTime(Date date)
  8. formatTime(Date time)
  9. formatTime(Date time)