Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SimpleDateFormat

 
Alik Elzin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want ot create a new instance of SimpleDateFormat with a pattern, which the user of the program gave. How do I know the pattern, given by the user, is a valid one ?
Thanks.
Alik
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you not able to pre-define the pattern, so that the user only have the 'right' ones to choose from?
Rene
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alik,
Unless I am misinterpreting your question, what (I think) you need is the "applyPattern()" method (of class "java.text.SimpleDateFormat"). It throws an exception if the supplied pattern is invalid. Please check the javadocs for more details.
Hope this has helped you.
Good Luck,
Avi.
 
Alik Elzin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rene,
thanks for the advise, but I want to give the user a free hand to choose his format.
 
Alik Elzin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avi,
I looked at the javadocs on java.text.SimpleDateFormat.applyPattern() and the method is not throwing an exception.
Thanks for the effort.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the javadoc for SDK 1.4.x it throws an exception.
Rene
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alik - look again. It throws IllegalArgumentException. Since this is a subclass of RuntimeException it's not required to be declared in a throws clause - but the javadoc does document it anyway, using the @exception tag.
[ January 01, 2003: Message edited by: Jim Yingst ]
 
Alik Elzin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not writting this earlier, but I'm using JDK 1.3.1.
The method applyPattern() in JDK 1.3.1 does not throw an exception.
Can you give a way to valid the pattern in JDK 1.3.1 ?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic