stuts2 字符串截取与格式化日期
1.
<s:if test="title.length()>20"> <s:property value="title.substring(0,20)+'...'"/> </s:if>
2.或者
<s:if test="%{title.length()>300}"> <s:property value="title.substring(0,300)+'...'"/> </s:if>
struts2中格式化输出数字和日期、截取小数点后两位数的方法 收藏 struts2中格式化输出数字和日期的方法,struts2截取小数点后两位数
1.写一个Messages.properties配置文件:
#number: global.format.money={0,number,#0.00##} global.format.money02={0,number,##0.00} #datetime: global.format.date={0,date,yyyy-MM-dd} global.format.time={0,date,HH:mm:ss} global.format.datetime={0,date,yyyy-MM-dd HH:mm:ss} global.format.datetime02={0,date,yyyy-MM-dd HH:mm}
其中#number为控制数字格式的,一般用于控制钱的位数;#datetime是控制时间格式
2.页面上:<s:text name="global.format.date"><s:param value="deployDate" /></s:text>
其中:<s:text name="global.format.date">控制你要显示的时间格式
<s:param value="deployDate" />是你要显示的时间
JSP文件 格式化时间: <s:text name="global.format.date"><s:param value="publishTime"></s:param></s:text> 格式化数字: <s:text name="global.format.money"><s:param value="price"/></s:text>
二:
<input type="text" value="<s:date name="deployDate" format="yyyy-MM-dd" />" />
其中name="deployDate"是你要显示的时间,format="yyyy-MM-dd"是显示的格式