This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Is there a way i can get the value in Calendar format or convert the above string into calendar format ?
You've got it in Calendar format (a GregorianCalendar instance to be precise). The output you show is what calendar.toString returns. Your problem is probably in how you try to cast it to a Calendar. Show us the code where you do that.
And when i looked into BeanUtils API, it says that using BeanUtils.getProperty or BeanUtils.getSimpleProperty() will return the value in String format thats why when i type cast the value to Calendar it throws a run time error.
Joined: Aug 05, 2005
So how did you print out the value you showed in your first post ?
Joined: Jun 18, 2009
using System.out.println(value) to see what was in that value.
Pawan Kalyan wrote:using System.out.println(value) to see what was in that value.
Okay. I see what your saying. The getProperty method calls toString on the object and then returns that String.
I'm afraid I don't know anything about the BeanUtils class, so i would say you need to either follow Junilu's advice and call bean.getDateOfBirth() directly, find another method in the BeanUtil class that returns the object rather than its String representation or (and this is definitely not recommended) parse the returned String to get the information you want.
Joined: Jun 18, 2009
I cant do bean.getDateOfBirth() becasue i am using this code in a common method to get values from bean and to set those values on other bean which have same variable names and types using reflection. thats why i was trying to see if there is any other way to get a property value of a java bean in Object or Calendar value if the property type is Calendar.
I hope i didnt confuse you and understand my condition.
If you make the types and property names on the source and target beans the same, the BeanUtils static methods copyProperty() or copyProperties() should do the trick. If the types are not the same on both, then you should rethink your design.