Java - Write code to get Date By Time Stamp long value in yyyy-MM-dd hh:mm:ss format

Requirements

Write code to get Date By Time Stamp long value in yyyy-MM-dd hh:mm:ss format

Demo

//package com.book2s;

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

public class Main {
    public static void main(String[] argv) {
        long timestamp = 41231232;
        System.out.println(getDateByTimeStamp(timestamp));
    }/*w  w w .  j av a  2 s.co m*/

    public static String getDateByTimeStamp(long timestamp) {
        if (timestamp != 0) {
            SimpleDateFormat sdf = new SimpleDateFormat(
                    "yyyy-MM-dd hh:mm:ss");
            String date = sdf.format(new Date(timestamp));
            System.out.println(date);
            return date;
        } else {
            return "";
        }
    }

    public static String getDateByTimeStamp(long timestamp, String format) {
        if (timestamp != 0) {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            String date = sdf.format(new Date(timestamp));
            return date;
        } else {
            return "";
        }
    }
}