Skip to content

Instantly share code, notes, and snippets.

@NKjoep
Created December 16, 2013 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NKjoep/7989220 to your computer and use it in GitHub Desktop.
Save NKjoep/7989220 to your computer and use it in GitHub Desktop.
JSP date manipulation sample: increase time give a date sample...
<%@ page contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="wp" uri="/aps-core" %>
<%@ taglib prefix="wpsa" uri="/apsadmin-core" %>
<%@ taglib prefix="wpsf" uri="/apsadmin-form" %>
<c:set var="random"><%= java.lang.Math.round(java.lang.Math.random() * 6) %></c:set>
<c:set var="startDate" value="${param.lastStreamTimestamp}" />
<fmt:parseDate value="${startDate}" pattern="yyyy-MM-dd HH:mm:ss SSSS" var="startDate" type="both" />
<c:forEach begin="0" end="${random}" varStatus="s">
<fmt:parseDate value="${param.lastStreamTimestamp}" pattern="yyyy-MM-dd HH:mm:ss SSSS" var="startDate" type="both" />
<c:set var="currentDate" value="${startDate}" />
<c:set var="currentDate_time"><jsp:getProperty name="currentDate" property="time" /></c:set>
currentDate unouched: <jsp:getProperty name="currentDate" property="time" />
<c:set var="currentDate_time" value="${currentDate_time + ((1000 * 60 * 60 * 25) * (random+1-s.index))}" />
<jsp:setProperty name="currentDate" property="time" value="${currentDate_time}" />
currentDate added <jsp:getProperty name="currentDate" property="time" />
currentDate date <fmt:formatDate value="${currentDate}" pattern="yyyy-MM-dd HH:mm:ss SSSS" />
<c:remove var="currentDate" />
--
</c:forEach>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment