Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in SimpleDateFormat

 
Saptarshi Chakraborty
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi folks ,
I am having a problem in SimpleDateFormat class. I have a method like this



running the code throws an exception like


Unparseable date: "Tue May 05 13:38:42 IST 2009"
at java.text.DateFormat.parse(Unknown Source)


Can any one figure out what is the problem here in this code?
and how can I convert the date to my desired format.
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What pattern are you using? Does the pattern match the input String?
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just what are you trying to do? Convert a Date into a Date? Why not just return the original Date object?

I think, given the method name, this is what you want:
 
Saptarshi Chakraborty
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I want to convert a Date into a Date with a specific format.
 
Saptarshi Chakraborty
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wrong in my approach.Date objects don't have a format.A date is the number of milliseconds since Jan 1st, 1970 UTC. It is a number. It has no format. SimpleDateFormat can parse it to a String with our desired format.
 
Vinoth Thirunavukarasu
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Refer this Example will help you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic