on 12-05-2013 12:05 PM
Hello Experts,
This is Fayaz.
Let me explain about the issue that i am facing .
In the output table i have a column which displays the date but the attribute type is String(On screen output : 20/09/2012).Because of string type sorting is not properly done(Done based on the string value not on the basis of date)
Can you please correct me where i did the mistake
Below code :
SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
java.util.Date date;
try{
date d=df.parse(string); //String returns date
ele.setDate_finc(df.format(d)); (Getting exception in this line) //Date_finc is of type Date
// i want same format after converting the string to date(i.e 20/09/2012)
}
catch(ParseException e)
{ }
}
Please let me know is there any alternative way for applying the filter without changing the attribute type from string to date
Can you please help me?
Thanks in Advance,
Regards
Fayaz Shaik
Hi,
In your code the line which is giving the error, you are using df.format() method which returns String instead Date which you are trying to set in the context attribute Date_finc which is of type Date.
You cannot assign String value to a Date attribute.
You have to set attribute as ele.setDate_finc(d);
Also for the display format of the data datatype, it will depend on the user configuration. You cannot change the display format of date with this code.
Regards,
Amol
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You haven't assigned your variable 'date' a value yet, other than that your code seems correct
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fayaz,
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String dateInString = "7/12/2013";
try {
Date date = formatter.parse(dateInString);
System.out.println(date);
System.out.println(formatter.format(date));
} catch (ParseException e) {
e.printStackTrace();
}
or
String startDateString = "20/06/2013";
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date startDate;
try {
startDate = df.parse(startDateString);
String newDateString = df.format(startDate);
System.out.println(newDateString);
}
catch (ParseException e)
{
e.printStackTrace();
}
Please try above code. Hope this is helpful !!!
Regards
Vijay K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.