Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Eugen
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE

Re: Convert String to date...

 

For me it is impossible to get this exception from current code:

 

if ( testField instanceof DateField ) {//Eugen: this operator already says that it's DateField
DateField convertDate = (DateField) testField; // Error : Cannot cast from Field to DateField
fieldString = Long.toString(convertDate.getDate());
}


Many java codes will be failed if instanceof returns true, but you get ClassCastException inside case.

Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: Convert String to date...

[ Edited ]

@Peter

It is a compile error and i am using 

 

String type =VerticalManager.getField(index).getClass().toString();

 

if(type.equals("net.rim.device.api.ui.component.DateField")) 

 

instead of 

 

if ( testField instanceof net.rim.device.api.ui.component.DateField )

 

Both should come out the same way right..???

Could this be a problem with the version . Am using Eclipse version 3.4.1 and JDE component version 4.5..

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: Convert String to date...

@RexDoug

HTTPDateParser supports only 3 different types.

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Convert String to date...

[ Edited ]

It supports dozens:

 

Parses a date string and returns the number of milliseconds since January 1, 1970, 00:00:00 GMT. The date is assumed to be of the format: "Wdy, DD Mon YY" "Wdy, DD Mon YYYY" "Wdy, DD Mon YY HH:MM:smileyfrustrated:S" "Wdy, DD Mon YY HH:MM:smileyfrustrated:S GMT" "Wdy, DD Mon YY HHMMSS" "Wdy, DD Mon YY HHMMSS GMT" "Wdy, DD Mon YYYY HH:MM:smileyfrustrated:S" "Wdy, DD Mon YYYY HH:MM:smileyfrustrated:S GMT" "Wdy, DD Mon YYYY HHMMSS" "Wdy, DD Mon YYYY HHMMSS GMT" "Wdy, Mon DD YY HH:MM:smileyfrustrated:S" "Wdy, Mon DD YY HH:MM:smileyfrustrated:S GMT" "Wdy, Mon DD YY HHMMSS" "Wdy, Mon DD YY HHMMSS GMT" "Wdy, Mon DD YYYY HH:MM:smileyfrustrated:S" "Wdy, Mon DD YYYY HH:MM:smileyfrustrated:S GMT" "Wdy, Mon DD YYYY HHMMSS" "Wdy, Mon DD YYYY HHMMSS GMT" "Wdy, DD Mon YY, HH:MM:smileyfrustrated:S" "Wdy, DD Mon YY, HH:MM:smileyfrustrated:S GMT" "Wdy, DD Mon YY, HHMMSS" "Wdy, DD Mon YY, HHMMSS GMT" "Wdy, DD Mon YYYY, HH:MM:smileyfrustrated:S" "Wdy, DD Mon YYYY, HH:MM:smileyfrustrated:S GMT" "Wdy, DD-Mon-YY HH:MM:smileyfrustrated:S" "Wdy, DD-Mon-YY HH:MM:smileyfrustrated:S GMT" "Wdy, DD-Mon-YY HHMMSS" "Wdy, DD-Mon-YY HHMMSS GMT" "Wdy, DD-Mon-YY, HH:MM:smileyfrustrated:S" "Wdy, DD-Mon-YY, HH:MM:smileyfrustrated:S GMT" "Wdy, DD-Mon-YY, HHMMSS" "Wdy, DD-Mon-YY, HHMMSS GMT" "Wdy, DD-Mon-YYYY HH:MM:smileyfrustrated:S" "Wdy, DD-Mon-YYYY HH:MM:smileyfrustrated:S GMT" "Wdy, DD-Mon-YYYY HHMMSS" "Wdy, DD-Mon-YYYY HHMMSS GMT" "Wdy, DD-Mon-YYYY, HH:MM:smileyfrustrated:S" "Wdy, DD-Mon-YYYY, HH:MM:smileyfrustrated:S GMT" "Wdy, DD-Mon-YYYY, HHMMSS" "Wdy, DD-Mon-YYYY, HHMMSS GMT" "Weekday, DD-Mon-YY HH:MM:smileyfrustrated:S" "Weekday, DD-Mon-YY HH:MM:smileyfrustrated:S GMT" "Weekday, DD-Mon-YY HHMMSS" "Weekday, DD-Mon-YY HHMMSS GMT" "Weekday, DD-Mon-YYYY HH:MM:smileyfrustrated:S" "Weekday, DD-Mon-YYYY HH:MM:smileyfrustrated:S GMT" "Weekday, DD-Mon-YYYY HHMMSS" "Weekday, DD-Mon-YYYY HHMMSS GMT" "Wdy Mon DD HH:MM:smileyfrustrated:S YYYY" "YYYY" (eg 1997) "YYYY-MM" (eg 1997-07) "YYYY-MM-DD" (eg 1997-07-16) "YYYY-MM-DDThh:mmTZD" (eg 1997-07-16T19:20+01:00) "YYYY-MM-DDThh:mm:ssTZD" (eg 1997-07-16T19:20:30+01:00) "YYYY-MM-DDThh:mm:ss.sTZD" (eg 1997-07-16T19:20:30.45+01:00) When parsing a date string using the abbreviated year pattern ("YY") it must interpret the abbreviated year relative to some century. It does this by adjusting dates to be within 80 years before and 20 years after the current time.

Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: Convert String to date...

[ Edited ]

Ah .. I dint check the bottom.. The first para in the API reference says 

 

 

A little utility class designed to parse dates in one of the three formats supported by HTTP 1.1. The formats are:

  • Sun, 06 Nov 1994 08:49:37 GMT (RFC 822, updated by RFC 1123)
  • Sunday, 06-Nov-94 08:49:37 GMT (RFC 850, obsoleted by RFC 1036)
  • Sun Nov 6 08:49:37 1994 (ANSI C's asctime() format) 
I stopped there when i saw none of them matched my requirement.

 

And what does Wdy stand for???

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Convert String to date...

[ Edited ]

Weekday.

 

I used this class to parse a non-standard date (coming from a web site) that was not listed in the "supported" formats, and it worked perfectly (to my surprise).

 

I would give it a try, probably take you 5 minutes to test.

 

Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: Convert String to date...

And plus none of them are in the format that i want...:smileysad:

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Convert String to date...

Why not write a parser that talks to Calendar?

Please use plain text.
Developer
nirmalsat
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: Convert String to date...

And i did try the HttpDateparse.  It kept returing 0...:manindifferent:

------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Please use plain text.
Developer
ydaraishy
Posts: 562
Registered: ‎09-30-2009
My Device: Not Specified

Re: Convert String to date...

I was suggesting you write your own parser, if that was directed to me.

Please use plain text.