在EL表达式或者Struts标签库中格式化日期对象,即将Date转换为yyyy-MM-dd格式

一、EL表达式

  首先,在jsp页面引入<fmt> tags,<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>。

  其次,将EL表达式作为fmt标签属性的value值。再增加pattern参数,为日期制定需要格式化的格式,如yyyy-MM-dd。例如:

<fmt:formatDate value="${object.dateproperty}" pattern="yyyy-MM-dd HH:mm"/> 

二、Struts标签库

  首先,在jsp页面导入Struts标签库即:。类似EL表达式,我们需要在s:date标签总指定format作为格式化日期的参数,同时将需要格式化的date属性指定为name属性的值,例如:

<s:date name="#object.dateproperty" format="yyyy-MM-dd HH:mm"/>

备注:name中写#object.dateproperty,而不能写object.dateproperty,必须加#。

附:未格式化显示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAisAAABhCAIAAACYkHZcAAAJjklEQVR4nO2d2YGjMBAFyYiICIhsCIZ82A9srKNbEj7QY7bqa8eAYPYhyi0EMwzDMAzDBgAAcC0DBgIAgC5gIAAA6AMGAgCAPmAgAADoAwYCAIA+YCAAAOgDBgIAgD5gIAAA6AMGAgCAPmAgAADoAwYCAB2WaRiGYVrCz9Z5HIZhGOfV2mJfGm9R2mRfFCzZd+k1bxxdtjd4GwwEADpYBioq6CmFeKG/xWNJuIfHR3WvNK8IrWAgANAhMNDTLSaBBKwaxjXQU0DzQyaVHay11TDSZ2AgAJAgudpPy5YNsS1T8JNtKM8cDxmZNVbtmNwBOqOgglNgIADQITbEUyS7AuKfing10N58yy2f+ACogX4EBgIAHZIaJbzzkt2FiXTyqIgeC20DRQoryeXYjhrox2AgANDhMFCt+hjnNbz+J8oxDXQ0SQ0kAwYCAB3y+zTL5DojqFCS4TXLQK/7RtRAMmAgANDhpYnieFq09qtimhbHK+O8bss0DONYNEoGNdCPwUAAIEEwt61hFC4YezsG5JKRuaDVcV63dR4fk7DbDeQcI8r5FhgIAHSIR+GSMbl8JttzhbwY2vJt1nXNxu1sottJ0xJrLHLQOo8f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