Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in parsing String into a particular Date format

 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried formatting a string into a particular Date format specified using the SimpleDateFormat class. But i wasn't successful in doing it. Below is the code which tried parsing the String



I get the following error message:



What might me the problem?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

String str="2009-02-09T16:40:07Z";

Z reperesents TIMEZONE , the String did not match It has to represent TIMEZONE and not 'Z'. try like

String str="2009-02-09T16:40:07GMT";

Refer API
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. I had been stuck with it for a long time.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You are welcome. and When you have stuck the best one can do is help himself rather than to wait for a thrid eye
Refer the API link to understand better
 
Mike Simmons
Ranch Hand
Posts: 3040
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternately, if your input string is supposed to end in Z (for Zulu time), you can tell the SimpleDateFormat to expect a literal 'Z' using single quotes, much like the literal 'T' it expects earlier:
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu Sadhasivam wrote:
You are welcome. and When you have stuck the best one can do is help himself rather than to wait for a thrid eye

Actually, just asking someone to help you look for the problem helps a lot. I can't even count the number of times I had a problem, asked somebody to help me look for it, and then found it while the other person was still looking over my shoulder. The presence of the other person alone can sometimes work miracles.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic