java - Change the date time format of an existing DateTime instance of Joda -
i have 2 date fields. user can take date jquery date-time picker converted utc format (via custom property editor of spring) , populated java bean upon submission of form.
these datetime
instances java bean retrieved org.apache.commons.beanutils.propertyutils
via reflection like,
final object object1 = propertyutils.getproperty(beanobject, firstdate); final object object2 = propertyutils.getproperty(beanobject, seconddate);
these objects type-cast datetime
.
if(object1!=null && object2!=null) { final datetime startdate=((datetime)object1).withzone(datetimezone.forid("asia/kolkata")); final datetime enddate=((datetime)object2).withzone(datetimezone.forid("asia/kolkata")); system.out.println("startdate = "+startdate+"\nenddate = "+enddate); }
this produces next output.
startdate = 2013-02-17t22:45:59.000+05:30 enddate = 2013-02-18t22:46:00.000+05:30
i need conver these dates format - dd-mmm-yyyy hh:mm:ss
the next approach have tried doesn't work.
datetime newstartdate=new datetime(startdate.tostring("dd-mmm-yyyy hh:mm:ss")); datetime newenddate=new datetime(startdate.tostring("dd-mmm-yyyy hh:mm:ss")); system.out.println("newstartdate = "+newstartdate+"\nnewenddate = "+newenddate);
it gives next exception.
java.lang.illegalargumentexception: invalid format: "17-feb-2013 22:45:59" malformed @ "-feb-2013 22:45:59"
so how convert these dates required format?
a datetime
doesn't have format. has value, number of milliseconds since 1st jan. 1970, , chronology. it's when transform datetime
string need take format. , know how already, since you're doing in question.
so you're trying doesn't create sense.
java datetime jodatime
No comments:
Post a Comment