使用fmt函数需在jsp中引入

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:formatDate value="${item.expDate}" pattern="yyyy-MM-dd"/>

报java.lang.IllegalArgumentException: Cannot convert 20131125 of type class java.lang.String to class java.util.Date

异常    因为${item.expDate}取出来是String类型,无法转换为Date类型

如下将能正常输出

<fmt:formatDate value="<%=new Date() %>" pattern="yyyy-MM-dd"/>

解决办法是,可先将String解析为Date 然后再格式化Date 。

<fmt:parseDate value="${item.expDate}" var="yearMonth" pattern="yyyy-MM-dd"/>

<fmt:formatDate value="${yearMonth}" pattern="yyyy-MM" /><!-- 这里的value只能是date类型-->

jstl format date的更多相关文章

  1. 【java】Date与String之间的转换及Calendar类:java.text.SimpleDateFormat、public Date parse(String source) throws ParseException和public final String format(Date date)

    package 日期日历类; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util. ...

  2. Ext.util.Format.date与Ext.Date.format区别, 转换时间戳

    在Extjs中装时间戳使用如下两种都可以: Ext.util.Format.date(time,'U'); Ext.Date.format(time, 'U'); 为了找到它们的区别,查看源代码,以E ...

  3. Ext.util.Format.date 时间格式的设置与转换

    Ext.util.Format.date 如下这段简单的代码:  var d = new Date(value.time); var s = Ext.util.Format.date(d, 'Y-m- ...

  4. jstl 处理Date 时间

    1.引入 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> < ...

  5. [React Intl] Format Date and Time Using react-intl FormattedDate and FormattedTime

    Using the react-intl FormattedDate and FormattedTime components, we’ll render a JavaScript Date into ...

  6. 杂记-格式化Date默认格式,日期加一天,jstl判断字符类型,ajax模拟from表单后台跳转页面,jstl访问数据库并在页面显示

    1.格式化Date默认格式 String str="Sun Oct 08 22:36:45 CST 2017"; SimpleDateFormat sdf = new Simple ...

  7. 使用date类和format类对系统当前时间进行格式化显示

    一:Date------------String 代码1:(代码二对显示出来的时间格式进行优化) package DateDemo; import java.text.SimpleDateFormat ...

  8. Java 8 Date Time API Example Tutorial – LocalDate, Instant, LocalDateTime, Parse and Format

    参考 Java 8 Date and Time API is one of the most sought after change for developers. Java has been mis ...

  9. Cannot format given Object as a Date

    这个小错挺有意思的,记录一下 导出Excel的时候,同事直接用 format …… 前提:数据库中该字段是 Timestamp ---- 2016-06-20 22:49:02.967 写个测试说明一 ...

随机推荐

  1. SQL Server更改排序规则的实现过程

    摘自: http://www.2cto.com/database/201112/115138.html 以下的文章主要向大家描述的是SQL Server更改排序规则的实现过程,以及在实现其实际操作过程 ...

  2. Asp.net 在网页编写C#代码示例-- 一个简单的web MsSql 命令执行环境

    在给一个客户做的系统上,因为要对数据库进行查看,但之前都是用TeamView来连接到客户的服务器进行数据库操作的 但最近客户那边的TeamView好像更改过密码导致我无法正常连接,而巧了客户的网官因为 ...

  3. JAVA:连接池技术说明以及MVC设计模式理解

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjgzMDgwNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  4. [Functional Programming] Write a simple version of Maybe

    Maybe has two types: Just / Nothing. Just() will just return the value that passed in. Nothing retur ...

  5. java基础知识精华

    转载:https://www.jianshu.com/p/6c078abb720f java基础知识 java内存模型 java运行时数据区域 hashMap 如何解决冲突 存储方式 冲突达到一定数量 ...

  6. Android 自己主动化測试(3)&lt;monkeyrunner&gt; 依据ID查找对象&amp;touch&amp;type (python)

    我在之前的两篇文章中用java来实现过 Android 自己主动化測试(1)怎样安装和卸载一个应用(java).Android 自己主动化測试(2)依据ID查找对象(java). 可是本质上都是用mo ...

  7. 使用Bundle进行VIM插件的管理

    http://www.oschina.net/p/vundle git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle ...

  8. Android相机基础基于camera2API

    前言 最近,在使用Android做一个照相机的开发.因为不能使用系统提供的相机应用,所以只能自己写一个.Android以前提供相机的api叫camera,不过在level 21被Google抛弃了.网 ...

  9. AsyncTask doinbackground onProgressUpdate onCancelled onPostExecute的基本使用

    对于异步操作的原理我就不讲了.在这我着重讲怎么使用异步操作的doinbackground onProgressUpdate onCancelled onPostExecute这四个方法 doinbac ...

  10. unity3d 版本控制场景合并。

    Editor→ProjectSettings→Editor Version Control Mode 设置为 "Visible Meta Files" Asset Serializ ...