rcmb
asked on
ADD 180 Days to Current Date
I use
SimpleDateFormat sdf_new = new SimpleDateFormat("MM/dd/yy yy");
String date = sdf_new.format(new Date());
to display the current date in a jsp page.
How can I add 180 days to the resultant value so that the date value would equal 180 days from the current date?
RCMB
SimpleDateFormat sdf_new = new SimpleDateFormat("MM/dd/yy
String date = sdf_new.format(new Date());
to display the current date in a jsp page.
How can I add 180 days to the resultant value so that the date value would equal 180 days from the current date?
RCMB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oh yeah... cal.add is better ;)
Calendar cal = Calendar.getInstance();
Date d = new Date();
cal.setTime(d);
cal.add(Calendar.DAY_OF_YE AR,180);
String date = sdf_new.format(cal.getTime ());
Date d = new Date();
cal.setTime(d);
cal.add(Calendar.DAY_OF_YE
String date = sdf_new.format(cal.getTime
ASKER
CEHJ,
I get the following error
cal.add(Calendar.DATE, 180);
^
and
sdf.format(cal.getTime());
^
am I missing an import or something?
RCMB
I get the following error
cal.add(Calendar.DATE, 180);
^
and
sdf.format(cal.getTime());
^
am I missing an import or something?
RCMB
ASKER
Here is my actual code now -- please point me in the correct direction.
SimpleDateFormat sdf_new = new SimpleDateFormat("MM/dd/yy yy");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 180);
sdf.format(cal.getTime());
String date = sdf_new.format(new Date());
RCMB
SimpleDateFormat sdf_new = new SimpleDateFormat("MM/dd/yy
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 180);
sdf.format(cal.getTime());
String date = sdf_new.format(new Date());
RCMB
import java.util.Calendar;
>>sdf.format(cal.getTime() );
needs to be assigned to something of course:
String yourDate = sdf.format(cal.getTime());
out.println(yourDate);
needs to be assigned to something of course:
String yourDate = sdf.format(cal.getTime());
out.println(yourDate);
ASKER
I already have import java.util.* in my import statement.
RCMB
RCMB
Please show your (exact) current code and errors
>>String date = sdf_new.format(new Date());
The above line of course just shows the current date
The above line of course just shows the current date
ASKER
Here is my exact code:
SimpleDateFormat sdf_new = new SimpleDateFormat("MM/dd/yy yy");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,180) ;
sdf.format(cal.getTime());
String date = sdf_new.format(cal.getTime ());
My errors are:
Generated servlet error:
Compiling 1 source file
C:\jboss-3.2.3\server\defa ult\work\M ainEngine\ localhost\ personnel\ jsp\prd_ea os_jsp.jav a:29 <idenitifer> expected
cal.add(Calendar.DATE,180) ;
^
C:\jboss-3.2.3\server\defa ult\work\M ainEngine\ localhost\ personnel\ jsp\prd_ea os_jsp.jav a:30 <idenitifer> expected
sdf.format(cal.getTime());
^
SimpleDateFormat sdf_new = new SimpleDateFormat("MM/dd/yy
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,180)
sdf.format(cal.getTime());
String date = sdf_new.format(cal.getTime
My errors are:
Generated servlet error:
Compiling 1 source file
C:\jboss-3.2.3\server\defa
cal.add(Calendar.DATE,180)
^
C:\jboss-3.2.3\server\defa
sdf.format(cal.getTime());
^
Try
java.util.Calendar cal = java.util.Calendar.getInst ance();
cal.add(java.util.Calendar .DATE, 180);
java.util.Calendar cal = java.util.Calendar.getInst
cal.add(java.util.Calendar
ASKER
Okay,
I have tried about every possible combination I can come up with. I am running JBoss 3.2.3 and not matter what I do the system fails on cal.add(
For some reason it gives me an identifier error.
I have searched the web and my syntext is correct (just as all of you have provided).
I tried just doing this
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,180) ;
and it fails with the same error code.
I tried adding the java.util.... to the beginning of the code and it does not change the error.
VBScript is so much easier :-(
Any ideas?
RCMB
I have tried about every possible combination I can come up with. I am running JBoss 3.2.3 and not matter what I do the system fails on cal.add(
For some reason it gives me an identifier error.
I have searched the web and my syntext is correct (just as all of you have provided).
I tried just doing this
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,180)
and it fails with the same error code.
I tried adding the java.util.... to the beginning of the code and it does not change the error.
VBScript is so much easier :-(
Any ideas?
RCMB
If you remove all code concerning Calendar, do the errors disappear?
ASKER
Yes - When I just have the SimpleDateFormat sdf_new...... and String date = .....
The page opens fine with the current date in the field box.
Curtis
The page opens fine with the current date in the field box.
Curtis
Better post your jsp, including headers
Try this page:
<%@ page language="java" contentType="text/html" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy yy");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,180) ;
%>
<%= sdf.format(cal.getTime()) %>
<%@ page language="java" contentType="text/html" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,180)
%>
<%= sdf.format(cal.getTime()) %>
Try this one:
Calendar cal = GregorianCalendar.getInsta nce();
instead of:
Calendar cal = Calendar.getInstance();
and the rest of the code remains the same.
Calendar cal = GregorianCalendar.getInsta
instead of:
Calendar cal = Calendar.getInstance();
and the rest of the code remains the same.
ASKER
Okay - thanks to all for the help but CEHJ's initial answer was all that was needed. The real problem was I did not have the Java bin folder in my system path. Once I added that my errors disappeared and all worked.
Thanks to all for your patience.
R/Curtis
Thanks to all for your patience.
R/Curtis
:-)
GregorianCalendar cal = new GregorianCalendar();
cal.set(Calendar.DATE, cal.get(Calendar.DATE) + 180);
String date = sdf_new.format(cal.getTime