Hi friends,i am getting the problem form last 10 days,but i didn't get the solution for that problem.
My problem is
In the Struts application i have created a select box(combo box) the text in the select box is large.when i want to go to select the text .the total text will appear. it is just like mouse over on the text.
i know how to create tool tip.for the select box i am having idea for that.
plese find that problem
Well you saw how I subtracted 30 days from the currect date by using the following...
rightNow.add(Calendar.DATE, -30);
You can add and sutract from the month and year fields as well.
rightNow.add(Calendar.MONTH, 2); // add two months
rightNow.add(Calendar.YEAR, -1); // subtract one year
One point that wasn't mentioned--the code below *automatically* takes care of rolling over the date. You don't need to keep track of leap years, months/years changing etc (amazing what sun's libraries can do, heh. I just discovered I don't have to write my own splitstring function)
Also, you mentioned earlier that you didn't want to include any jars...I don't quite follow what you're saying. For a jsp, all you need at the top is: <%@ page import="java.util.GregorianCalendar" %>
Then just get an instance of the class & use the add method.
> Well you saw how I subtracted 30 days from the
> currect date by using the following...
> > rightNow.add(Calendar.DATE, -30);
>
>
> You can add and sutract from the month and year
> fields as well.
> > rightNow.add(Calendar.MONTH, 2); // add two months
> rightNow.add(Calendar.YEAR, -1); // subtract one
> year
>
hmmm none of that code seems to work, even with <%@ page import="java.util.GregorianCalendar" %> included
the problem with that code is it will nock back each date, month and year all individual, i want it all to work together as the following:
for example i would like 30 days in the past from todays date:
2006/01/16
which would return
2005/12/14
So basically i set i want to go back 30 days, but the month AND year also change depending on the date if we need to roll back to the previous month or even the previous year
Thanks
Tom
that doesnt help.
five minutes of somebodys time would be fantastic in a script that would work to do the above.
it seems not many people like to help others who are new to jsp as i have seen in many posts, which probably proves a point and why many prefer php and the community that comes with it.
shame really
The solution was given to you so I'm not sure what your problem is.
It appears to me that you have simply demonstrated what all new programmers do in this forum; you want someone to write your code for you and your too **** lazy to read the API for yourself.
http://java.sun.com/j2se/1.5.0/docs/api/index.html
The following code rolls back the date by 30 days and at the same time automatically calculates the correct year and month.
import java.util.*;
import java.text.*;
public class DateTest {
public static void main(String[] args){
DateTest d = new DateTest();
d.doWork();
}
public DateTest(){}
public void doWork(){
System.out.println("Peforming date rollback...");
// get current data & time
GregorianCalendar gcal = new GregorianCalendar();
System.out.println("Date: " + formatDate(gcal.getTime(),"MM/dd/yyyy HH:mm:ss a"));
// roll back 30 days
gcal.add(Calendar.DATE,-30);
System.out.println("Date: " + formatDate(gcal.getTime(),"MM/dd/yyyy HH:mm:ss a"));
}
// formats a date, see SimpleDateFormat class for futher information
private String formatDate(Date d, String format){
if (d != null) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
FieldPosition pos = new FieldPosition(0);
StringBuffer buf = new StringBuffer();
buf = sdf.format(d,buf,pos);
return buf.toString();
}
return "";
}
}
slenzi
I know it is irritating when new java developers need to be spoon fed but it does really help sometimes.
Fantastic answer.
I have been battling with Java Dates and wondering how to convert between Date and GregorianDate etc.
This is a great response.
Tkman