Calculate the difference in days between two dates using JSTL - jstl

I have set two dates using jstl. One is a current date and other is 7 days from now.
<jsp:useBean id="now" class="java.util.Date" />
<fmt:formatDate pattern="MM/dd/yyyy" value="${now}" var="nowDate"/>
<jsp:setProperty name="weekDate" property="time" value="${weekDate.time + 604800000}"/>
<fmt:formatDate pattern="MM/dd/yyyy" value="${weekDate}" var="weekDate"/>
I want to be able to find the difference between two days
I used the code shown below using code below , but
<fmt:formatDate pattern="MM/dd/yyyy" value="${(weekDate.time - nowDate.time) / (1000*60*60*24)}" var="dateDifference"/>
${dateDifference}
I get error saying
Property 'time' not found on type java.lang.String
How can I find the difference in days for the two dates?

use original objectname.time and parseNumber because we require # of days.

Related

JSTL cutsom date format using fmt tag [duplicate]

This question already has an answer here:
How to format date in JSTL
(1 answer)
Closed 7 years ago.
I need a date format like this.
11 November ,2015
I have tried using fmt tag.
<fmt:formatDate value="${Attr['DATE']}" type="both" dateStyle="long" />
the output is
November 11, 2015 12:00:00 AM.
How can i do that? Please help me.
Can i use any kind of pattern attribute?
Hint: fmt:formatDate has a pattern attribute too.
Try <fmt:formatDate pattern="dd M ,yyyy" value="${Attr['DATE']}" /> or <fmt:formatDate type="date" dateStyle="long" value="${Attr['DATE']}" />

JSTL: Dynamic number currency, change the pattern and keep it dynamic?

I'm trying to show a currency dynamicly, that works totally fine!
But I'd like to change the pattern from "SFr. 150'000.00" to "150'000.00 SFr." (and still keep it dynamicly!)
Any suggestions how I could do that?
Here is the code:
<fmt:setLocale value="${pageContext.request.locale}" scope="session" />
<fmt:formatNumber type="currency" value="${investVolume}" />
Thanks in advance!
<fmt:formatNumber type="currency" value="${investVolume}" pattern="###,###.## ¤"/>
The pattern attribute follows DecimalFormat rules.
The ¤ in the pattern represents the currency symbol.
Although I'm not sure if that ' would show in an upper or lower position this should be the way to go.

ace:dateTimeEntry converts invalid date to its another date

I have an ace:dateTimeEntry component as below :
<ace:dateTimeEntry id="surveyDate" partialSubmit="true" renderAsPopup="true"
value="#{maintainAppointmentManagedBean.surveyNewDate}"
pattern="dd/MM/yyyy" showButtonPanel="true" navigator="true"
valueChangeListener="#{maintainAppointmentManagedBean.surveyDateChangeListener}">
</ace:dateTimeEntry>
When I manually enter an invalid date such as 21544/10/2012, icefaces converts it to some acceptable format such as 10/12/2020 or similar. It must be doing some background calculation due to which it converts the invalid date to some other date. When it reaches my own validator, the date is already converted into some other date thus my validation has no effect and no message is displayed regarding the invalid date format. There is no JIRA raised to address this. Before I raise this as a bug has anyone else faced this problem or have any solution.
Also, the problem does not occur when pattern="dd/MM/yyyy hh:mm". It occurs only when pattern is pattern="dd/MM/yyyy"
Thanks,
Dakshata Gulkhobare
I tried adding lenientParsing="false" into ace:dateTimeEntry
and it works for me.
dateTimeEntry

Using f:validateRegex and p:inputMask together

I am trying to make a regex check for my time input text and also I am trying to mask the input. I don't know if both can be done at the same time with this code:
<p:inputMask mask="99:99" size="5" maxlength="5" required="true" requiredMessage="#{account_req_txt}" value="#{user.accountNo}">
<f:validateRegex pattern="[01]?[0-9]|2[0-3]):[0-5][0-9]"/>
<p:ajax event="blur" update="sysMsg" />
</p:inputMask>
I am getting "must be a number consisting of one or more digits." error. What is wrong with above code?
How exactly is the "account number" as represented by #{user.accountNo} a time? That part is confusing. In any way, the error suggests that the accountNo is actually a Number like Integer, Long, etc, not a String.
Perhaps you meant to bind it to #{user.time} or something else. At least, the value must be bound to a String, otherwise you need to create a Converter to convert between a String in 99:99 representation to a number type in 9999 representation.

Looking for JSTL Taglib calculate seconds between two dates

I'm looking for a taglib to use for calculating how many seconds there was between two dates.
You just do that with EL:
<jsp:useBean id="now1" class="java.util.Date" />
<jsp:useBean id="now2" class="java.utli.Date" />
The difference is: ${now1.time/1000) - (now2.time/1000)}
That's just a simple compilable example -- in real life, the two dates would hold different values.

Resources