Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Format Jdatechooser to yyyy-MM-dd

 
Andras Lakos
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guys ! I m really stuck with Jdatechooser. What i need is to format the Date from Jdatechooser to yyyy-MM-dd than pick up the year with the split Method. But i got always a NullException on the line "String s=sdf.format(d);". Please any suggestion !




[HENRY: Fixed code tags]
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the full stack trace for the exception?
Either 'd' is null or 'sdf' is...since sdf has only just been created then it has to be 'd'.
 
Paul Clapham
Sheriff
Posts: 21548
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't recommend using that way of extracting the year from the selected date. Assuming you are using Java 8, I would convert the java.util.Date object to a java.time.ZonedDateTime and get the year from that:



But as Dave implies, that isn't going to work either if you're getting a null value from your JDateChooser. If that's your problem you should find out why it happens and plan to deal with it when it does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic