• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.date Issue  RSS feed

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have Date in String like "09/22/2016", but I require that Date in new format "Sept 22, 2016". I tried with below code.



But I am not getting proper result.

I am getting result is "Dec 27, 2016".
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is because you are incorrectly using upper-case letters in the date format strings.

you should use "dd" instead of "DD" for the days component; "DD" means "day in year", not "day in month". Also, you should use "yyyy" instead of "YYYY" for the years component. See the API documentation of SimpleDateFormat for a detailed explanation.

 
Roopesh Rana
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks , That was the problem.
 
Saloon Keeper
Posts: 7994
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unrelated to your issue, but is there a reason you're using java.util.Date instead of java.time.LocalDate?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!