时间(毫秒数)转换
(有导入java.text.*;) (1184236817062是当前时间的毫秒数)
SimpleDateFormat sdfs = new SimpleDateFormat( " ",Locale.SIMPLIFIED_CHINESE);
sdfs.applyPattern( "yyyy-MM-dd HH:mm:ss ");
String endTime = sdfs.format( "1184236817062 ");
out.println(endTime);
为什么会出现下面的错误呢!?
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Cannot format given Object as a Date
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.IllegalArgumentException: Cannot format given Object as a Date
java.text.DateFormat.format(DateFormat.java:279)
java.text.Format.format(Format.java:133)
org.apache.jsp.shVnetpay_jsp._jspService(shVnetpay_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
------解决方案--------------------String endTime = sdfs.format(new java.util.Date(1184236817062));
------解决方案--------------------楼上的说得很对,SimpleDateFormat 既然有个 Date 在其中,它的 format 是不能放入字符串的,而且,那13个数字还不是字符串,是个long型的数值,需要先用楼上的方法构造一个 Date 类型再进行格式化的。
------解决方案-------------------- SimpleDateFormat date_format = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss ");
String tomorrowDate = date_format.format(new Date(millsLong));
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html