I am having trouble formatting date in java.
I have a shopping class that has item name in string, quantity in int and a date in Date.
In the run class I am trying to run this query.
Date date = new Date(202020);
SimpleDateFormat dateformat = new SimpleDateFormat("dd-mm-yy");
String date1 = dateformat.format(date);
Shopping shoplist1 = new Shopping ( "iphone", 2, date);
When I try to create a new shopping entery with the date the date does not format. I don't know why but it gives me Thu Jan 01 01:03:22 GMT 1970.
From your comment :
"I tried to add date 1, but it wouldn't allow it. It says string can not be converted to date"
You are passing string to your constructor but looks like it can take java.util.Date object
Shopping shoplist1 = new Shopping ( "iphone", 2, date);
Change your constructor signature to take a String object
OR
Pass the date object and perform the formatting in any other relevant location