1

I am getting the string like : java.util.GregorianCalendar[time=1407440700000,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=7,WEEK_OF_YEAR=32,WEEK_OF_MONTH=2,DAY_OF_MONTH=8,DAY_OF_YEAR=220,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=2,AM_PM=0,HOUR=1,HOUR_OF_DAY=1,MINUTE=15,SECOND=0,MILLISECOND=0,ZONE_OFFSET=19800000,DST_OFFSET=0] I want to cast into GregorianCalendar

Below code giving me the exception :

Object publishDateGen =  (Object)publishedDate;
GregorianCalendar calanderFromPublishedDate = (GregorianCalendar)publishDateGen;

Here publish date is the the string need to convert.

Thanks

Vivek Dhiman
  • 1,967
  • 6
  • 46
  • 82
  • 3
    Why do you have a `String` like that? You cannot **cast** a `String` to ` GregorianCalendar`. – Sotirios Delimanolis Aug 09 '14 at 16:39
  • 1
    There is no stock parser that takes the output of `GregorianCalendar.toString()` and yields a `GregorianCalendar`. If you are trying to serialize values using `toString` you should instead look into other Java serialization mechanisms. – Mike Samuel Aug 09 '14 at 16:40
  • Or parse it by yourself. You misuse terms `cast` in your expectations. – dmitry Aug 09 '14 at 16:42
  • `` Have you tried `GregorianCalender.deserialize()` yet? – Unihedron Aug 09 '14 at 16:43
  • First, figure out why the upstream code is just printing out the `toString`. – chrylis -cautiouslyoptimistic- Aug 09 '14 at 16:55
  • Where are you getting that string value from? – Jim Garrison Aug 09 '14 at 16:55
  • The problem is, I want to send GregorianCalendar object to my tag class. . when i retrieve this in tag class it gives me string as i posted in my question. How can i get this as GregorianCalendar object in my tag class, so to avoid conversion. – Vivek Dhiman Aug 09 '14 at 16:57
  • possible duplicate of [Using GregorianCalendar with SimpleDateFormat](http://stackoverflow.com/questions/10829942/using-gregoriancalendar-with-simpledateformat) – Basil Bourque Aug 09 '14 at 17:12
  • I also made changes in my tag class and tld file. Make the publishedDate of type GregorianCalendar, but in that case getting error no such method (Ljava/lang/String;)V – Vivek Dhiman Aug 09 '14 at 17:17
  • no such method (Ljava/lang/String;)V , now removed, & issue is solved after deleting that tag class and remove form tld file, with new class and new configuration in tld. – Vivek Dhiman Aug 09 '14 at 17:25

0 Answers0