码迷,mamicode.com
首页 > 其他好文 > 详细

String强制转换为Date,freemarker标签里date数据的显示问题

时间:2017-08-16 21:56:34      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:blog   rac   marker   转换   int   this   style   tle   smi   

String强制转换为Date,freemarker标签里date数据的显示问题

 

http://blog.sina.com.cn/s/blog_617f5d090101ut63.html

(2014-05-16 16:44:34)
  分类: 工作

解决了两个问题

1、

String强制转换为Date

SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");    String dateStr = request.getParameter("upmdateaa");       Date date =null;         if(dateStr != null && !dateStr.equals("")){      try {         date = format.parse(dateStr);      } catch (ParseException e) {       e.printStackTrace();      }

其中

SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

如果格式不对 则date就会为空

例如:SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");如果输入的dateStr为“2014-05-15”则date就会为空

2、freemarker标签里date数据的显示问题

${(ads.upAdsDate)?if_exists}会出现显示错误

错误日志:

Can‘t convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string. or ?string(format) built-in with this date. The problematic instruction:

更改为以下代码则正常

${ads.upAdsDate?string(‘yyyy-MM-dd HH:mm:ss‘)}

 

String强制转换为Date,freemarker标签里date数据的显示问题

标签:blog   rac   marker   转换   int   this   style   tle   smi   

原文地址:http://www.cnblogs.com/sky20080101/p/7375622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!