Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅使用JSP获取当前时间小时数_Jsp_Jstl - Fatal编程技术网

如何仅使用JSP获取当前时间小时数

如何仅使用JSP获取当前时间小时数,jsp,jstl,Jsp,Jstl,如何仅使用JSP获取当前时间?我无法控制bean,但我想使用当前时间(特别是24小时格式的小时数)进行比较 我有一个豆子和一个时间 ${Qlist.beginTime} <---- e.g. 1440 ( 14:40 ) ${Qlist.beginTime}您应该使用 <jsp:useBean id="date" class="java.util.Date"/> <fmt:formatDate var="time" value="

如何仅使用JSP获取当前时间?我无法控制bean,但我想使用当前时间(特别是24小时格式的小时数)进行比较

我有一个豆子和一个时间

 ${Qlist.beginTime} <---- e.g. 1440 ( 14:40 )

${Qlist.beginTime}您应该使用

<jsp:useBean id="date" class="java.util.Date"/>

<fmt:formatDate var="time"  
                value="${date}"
                pattern="HHmm"/>
<br/>${time}


${time}
我不会在JSP中使用这种逻辑。最好在bean中执行此操作:

public boolean isRunning(){
  return this.beginTimeInt < currentTimeInt;
}
public boolean isRunning(){
返回this.beginTimeInt
因此,您可以在JSP中这样使用它:

<c:if test="${myBean.running}">
  It's running!
</c:if>

它在跑!
为什么这样更好?假设您需要更多的需求才能运行bean,例如,它需要得到批准,并且有一个结束时间。然后,您需要在JSP中的任何地方添加条件,检查bean是否正在运行,而这意味着如果您想在bean中拥有逻辑,只需进行简单的更改。因此,您的灵活性会降低,JSP的可读性也会降低

<c:if test="${myBean.running}">
  It's running!
</c:if>