public static String getDateString(String lDate) { String x = lDate.trim(); String retStr = null; if (x == null || x == "") { x = "0"; } if (x != "0") { x = x + "000"; long idate = Long.parseLong(x); Date date = new Date(idate); DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT); retStr = df.format(date); } else { Date date = new Date(); SimpleDateFormat formater = new SimpleDateFormat(); formater.applyPattern("yyyy-M-dd"); retStr = formater.format(date); } return retStr; } System.out.println(getDateString("1252641537"));