Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

SimpleDateFormat

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the javadoc for SDK 1.4.x it throws an exception.
Rene
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic