【问题标题】:Convert Epoch Time to a date format in JSP在 JSP 中将纪元时间转换为日期格式
【发布时间】:2012-12-17 16:57:19
【问题描述】:

请告诉我如何将纪元时间(例如 - 1355893200000)转换为 JSP 中的 mm/dd hh:mm AM/PM 格式。

【问题讨论】:

    标签: jsp date-format epoch


    【解决方案1】:

    方案一(三个startDate保持不变):

    <jsp:useBean id="startDate" class="java.util.Date" />
    
    <jsp:setProperty name="startDate" property="time" value="${record.startDate}"/>
    
    <fmt:formatDate value="${startDate}" type="date" dateStyle="long"/>
    

    解决方案 2:

    // item is long, don't pass testing, is EL support Date Type init Object??
    
    <fmt:formatDate value="${Date(item)}" pattern="yyyy-MM-dd hh:mm:ss"/>
    

    fmt:parseDate 使用SimpleDateFormat 从字符串中解析日期。 Date 可以从 Date date = new Date (Long.parase(epochString)) 构造

    JSP 版本通常与 servlet 版本齐头并进,如下所示:

    Servlet 2.5 uses JSP 2.1 
    Servlet 2.4 uses JSP 2.0 
    Servlet 2.3 uses JSP 1.2 
    Servlet 2.2 uses JSP 1.1 
    Servlet 2.1 uses JSP 1.0 
    

    也许有帮助:

    参考:

    jstl code repo

    【讨论】:

      【解决方案2】:

      您可以使用 JSTL Core fmt:formatDate 标签。更多信息http://www.tutorialspoint.com/jsp/jstl_format_formatdate_tag.htm

      【讨论】:

      • fmt:formatDate 是否格式化纪元时间?它似乎对我不起作用。
      • 你可以这样做
      【解决方案3】:

      您可以查看 this 以将 unix 时间戳转换为 Java Date 对象。

      要格式化日期,您可以使用SimpleDateFormat

      例如

      SimpleDateFormat format = new SimpleDateFormat("MM/dd hh:mm aaa");
      String formatted = format.parse(myDate);
      

      【讨论】:

      • 我只想使用 JSTL 标签
      猜你喜欢
      • 2015-01-23
      • 2019-11-14
      • 2018-05-16
      • 2014-01-25
      • 2018-09-21
      • 2018-04-24
      • 2011-12-06
      • 2012-09-06
      • 1970-01-01
      相关资源
      最近更新 更多