• Post Reply Bookmark Topic Watch Topic
  • New Topic

Date Format mm/dd/yyyy parsing mm/dd/yyyyy(5 digit year)  RSS feed

 
Mahadevan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have declared private static DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

df.parse("12/12/20151") was executing fine. It should not be parsed as per the date format. I have tried with df.setLenient(false) and df.setLenient(true). But it was parsing successfully.
Do I need to manually check for the length of the string?
Is that an api issue?

Regards
Maha
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read your private messages about a JavaRanch administrative issue?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you might want your code to still work in 10000 years time!

I suspect that could be the point. 20151 is a valid year.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to assume that "yyyy" means that the year should have 4 digits - that is not the case. Read the javadocs of the SimpleDateFormat class to find out how the pattern is interpreted for years.
 
Mahadevan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your info. I have refered the Javadoc and if yyyy in pattern means any number.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read Jesper's post ? Check your private messages.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!