get HH:mm Format Time - Java java.util

Java examples for java.util:Date Format

Description

get HH:mm Format Time

Demo Code


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

import java.util.Date;
import java.util.Locale;

public class Main {
    public static void main(String[] argv) throws Exception {
        long time = 2;
        System.out.println(getHMFormatTime(time));
    }/*w  ww  . j a v a2s .  c  om*/

    public static String getHMFormatTime(long time) {
        return getFormatTime("HH:mm", time);
    }

    public static String getFormatTime(String formatter, long time) {
        SimpleDateFormat format = new SimpleDateFormat(formatter,
                Locale.getDefault());
        return format.format(new Date(time));
    }
}

Related Tutorials