Java - Write code to format Timestamp in long value to string in yyyy-MM-dd HH:mm:ss format

Requirements

Write code to format Timestamp in long value to string in yyyy-MM-dd HH:mm:ss format

Demo

//package com.book2s;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class Main {
    public static void main(String[] argv) {
        long time = 12312342;
        System.out.println(simpleDateTimeStr(time));
    }// w  w w  .jav a2 s  . c o  m

    private static SimpleDateFormat simpleDateTimeFormate = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");

    public static String simpleDateTimeStr(long time) {
        if (time > 0) {
            return simpleDateTimeFormate.format(new Timestamp(time));
        } else {
            return "--:--";
        }
    }
}