public class Book {
Calendar dateOfPublish;
Book(Calendar dateOfPublish, ...){}
public Calendar getDateOfPublish() {
return dateOfPublish;
}
public void setDateOfPublish(int day, int month, int year) {
this.dateOfPublish = dateOfPublish;
}
public String toString() {
return Date Of Publish=" + dateOfPublish.YEAR + "/" + dateOfPublish.MONTH + "/" +
dateOfPublish.DATE;
}
}
I've tried to instantiate a book object using this this as argument in the Calendar data fielld.
new Book(new GregorianCalendar(2018,3,20));
But when i display the object with toString(), it displays
Results:
Date Of Publish=1/2/5
I've searched through internet, seeing some people use SimpleDateFormat
, but can it be done in an entity class? Or is there any better Date/Calendar class that i should use?