• Post Reply Bookmark Topic Watch Topic
  • New Topic

Format Jdatechooser to yyyy-MM-dd  RSS feed

 
Andras Lakos
Greenhorn
Posts: 18
  • 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 Foreman
Posts: 3006
37
  • 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: 22708
43
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!