I am trying to output the current date format into:
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
, but it is outputting like this:
Fri Dec 02 14:03:59 AEST 2016
Here is my code:
JDateChooser datePurchased = new JDateChooser();
DateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");
Date newDate = new Date();
datePurchased.setDate(newDate);
I am now printing the result like this:
System.out.println(newDate.toString());
But this does not print out what I want, as per above.
My goal output is: 02/12/2016
, how do I go about doing this, I've tried looking around but I cannot find the likes to solve my problem.
Thank you in advance.
You are printing the date but no using the formatter, you need to do:
String pattern = "dd-MM-yyyy";
DateFormat formatter = new SimpleDateFormat(pattern);
System.out.println(formatter.format(newDate));
if your goal output is: 02/12/2016 then in the pattern in the format incorrect, you will need to use slash and not hyphens
use instead dd/mm/yyyy