简体   繁体   English

在jsp中格式化datetime字符串?

[英]Format datetime string in jsp?

How can I format string1 to string2 in jsp? 如何在jsp中将string1格式化为string2? Please help me resolve this issue 请帮我解决这个问题

String string1 = "2013-10-22 10:00:00',4";
String string2 = "10.00,4";

Add the taglib directive to your jsp: 将taglib指令添加到您的jsp中:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

You should be able to format the first string to the second string as follows. 您应该能够将第一个字符串格式化为第二个字符串,如下所示。 First convert string1 to an intermediate date: 首先将string1转换为中间日期:

<c:set var="string1" value="2013-10-22 10:00:00',4" />
<fmt:parseDate value="${string1}" var="theDate" 
     pattern="yyyy-MM-dd HH:mm:ss'',S" />

Then format it to the required format: 然后将其格式化为所需的格式:

<fmt:formatDate value="${thedate}" pattern="hh.mm,S" var="string2"/>

Which you can then use: 然后可以使用:

<c:out value="${string2}" />

使用JSTL <fmt:formatDate>标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM