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')}