jsp时间格式转换

我在数据库中存的时间值是 10位数字(php的time()函数寸入的)
比如1227668789->2008-11-26
怎么用jsp或java把这个字符串装换成时间呢
希望大哥们指教

第1个回答  推荐于2016-04-12
public static String mk_time(String time,String type)
{
String str=time+"123";//加123只是为了凑足毫秒
Date date=new Date(Long.parseLong(str));
SimpleDateFormat dateFormat = new SimpleDateFormat(type);//type yyyy-MM-dd
// out.println(dateFormat.format(date));//2006-11-23*/
return dateFormat.format(date);//2006-11-23*/
}本回答被提问者采纳
第2个回答  2016-02-04
jsp中要显示php的time()函数存入的时间,需要转换成java date。

注意:time()存入的格式是milliseconds。
举例说明:
String x = "1086073200000";
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
long milliSeconds= Long.parseLong(x);
System.out.println(milliSeconds);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
//格式化输出日期
System.out.println(formatter.format(calendar.getTime()));
第3个回答  2008-11-26
怎么一会儿是jsp一会儿又是php?php我不会,反正java里转换是下面这样子:
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
相似回答