| Author |
SimpleDateFormat
|
Alik Elzin
Greenhorn
Joined: Sep 19, 2002
Posts: 15
|
|
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
Joined: Oct 12, 2001
Posts: 1179
|
|
Are you not able to pre-define the pattern, so that the user only have the 'right' ones to choose from? Rene
|
Regards, Rene Larsen
Dropbox Invite
|
 |
Avi Abrami
Ranch Hand
Joined: Oct 11, 2000
Posts: 1112
|
|
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
Joined: Sep 19, 2002
Posts: 15
|
|
Hi Rene, thanks for the advise, but I want to give the user a free hand to choose his format.
|
 |
Alik Elzin
Greenhorn
Joined: Sep 19, 2002
Posts: 15
|
|
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
Joined: Oct 12, 2001
Posts: 1179
|
|
In the javadoc for SDK 1.4.x it throws an exception. Rene
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
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 ]
|
"I'm not back." - Bill Harding, Twister
|
 |
Alik Elzin
Greenhorn
Joined: Sep 19, 2002
Posts: 15
|
|
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
Joined: Jan 30, 2000
Posts: 18670
|
|
|
|
 |
 |
|
|
subject: SimpleDateFormat
|
|
|