This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem in parsing String into a particular Date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in parsing String into a particular Date format" Watch "Problem in parsing String into a particular Date format" New topic
Author

Problem in parsing String into a particular Date format

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

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?

Mohamed Sanaulla | My Blog
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


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

Joined: Sep 08, 2007
Posts: 3064
    
  33

Thanks a lot. I had been stuck with it for a long time.
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


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

Joined: Mar 05, 2008
Posts: 2986
    
    9
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

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem in parsing String into a particular Date format
 
Similar Threads
SimpleDateFormat parse method
problem formatting date string
Date/SimpleDateFormat help need
Problem in Coverting one Date Format to Other date Format
Java date conversion confusion...