当前位置: 代码迷 >> Java Web开发 >> 时间(毫秒数)转换解决方法
  详细解决方案

时间(毫秒数)转换解决方法

热度:524   发布时间:2016-04-17 14:05:09
时间(毫秒数)转换
(有导入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.daimami.com/search?q=317
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!