zoukankan      html  css  js  c++  java
  • String强制转换为Date,freemarker标签里date数据的显示问题

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

  • 相关阅读:
    PHP实现邮件的自动发送
    为PostgreSQL的表自动添加分区
    django
    django的logging模块
    job
    python 类的方法带的self理解
    java
    choice_set的理解
    django
    proxy_next_upstream带来的坑和加载sticky模块
  • 原文地址:https://www.cnblogs.com/sky20080101/p/7375622.html
Copyright © 2011-2022 走看看