freemarker標籤裏date數據的顯示問題



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數據的顯示問題

$(對象.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:

更改爲以下代碼則正常

$(對象.date?string('yyyy-MM-dd HH:mm:ss'))

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章