Java SQL Timestamp format to String like "1969-12-31 19:25:12"
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 ww . j a v a 2 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 "--:--"; } } }