Java - Write code to convert Date value in long to String

Requirements

Write code to convert Date value in long to String

return a string in format yyyy/MM/dd

Hint

Use SimpleDateFormat

Demo

//package com.book2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static void main(String[] argv) {
        long time = 42;
        System.out.println(DateStr(time));
    }//from   www .j  a v  a 2s  . co m

    public static String DateStr(long time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        Date date = new Date(time * 1000);
        String timeStr = format.format(date);
        return timeStr;
    }
}