aspose file tools
The moose likes Java in General and the fly likes Date Format mm/dd/yyyy parsing mm/dd/yyyyy(5 digit year) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Date Format mm/dd/yyyy parsing mm/dd/yyyyy(5 digit year)" Watch "Date Format mm/dd/yyyy parsing mm/dd/yyyyy(5 digit year)" New topic
Author

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

Mahadevan
Greenhorn

Joined: Oct 05, 2005
Posts: 6
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
Bartender

Joined: Aug 16, 2005
Posts: 12907
    
    3

Did you read your private messages about a JavaRanch administrative issue?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3786
    
    1

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

Joined: Oct 14, 2008
Posts: 1337
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

Joined: Oct 05, 2005
Posts: 6
Thanks for your info. I have refered the Javadoc and if yyyy in pattern means any number.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14669
    
  11

Did you read Jesper's post ? Check your private messages.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Date Format mm/dd/yyyy parsing mm/dd/yyyyy(5 digit year)
 
Similar Threads
Code review required for converting dateformat
How do I pad a timestamp string with 0s?
problem formatting date string
Convert date in difference format
validating Date field and saving into DB?