get yyyy/MM/dd HH:mm Format Time - Java java.util

Java examples for java.util:Date Format

Description

get yyyy/MM/dd 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(getYMDHMFormatTime(time));
    }//from  w ww.  ja  va 2 s.  c  om

    public static String getYMDHMFormatTime(long time) {
        return getFormatTime("yyyy/MM/dd 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