此设置不起作用。当我打印出 v1 时,我得到了错误格式的错误日期,因为它包含的时间为 00:00:0000。
有没有办法覆盖 Date 对象的格式化方法(如果有的话)?
public class Vehicle
{
//**********Declarations**********
private String manufacturer;
private String model;
//********** Declaring Customer object **********
private Customer customer = null;
private String VIN;
private Date dateOfManufacture;
private Date dateOfSale = null;
private Boolean sold = false;
private char taxBand;
private int costOfVehicle;
//**********Constructor**********
public Vehicle(String man, String mod, Customer custName, String VIN, String dateOfMan, char taxBand, int costOfVehicle)
{
this.manufacturer = man;
this.model = mod;
this.customer = custName;
this.VIN = VIN;
Date newDate = new Date(dateOfMan);
this.dateOfManufacture = newDate;
this.taxBand = taxBand;
this.costOfVehicle = costOfVehicle;
}
public Date getDateOfManufacture()
{
return dateOfManufacture;
}
public void setDateOfManufacture(Date dateOfManufacture)
{
this.dateOfManufacture = dateOfManufacture;
}
public Date getDateOfSale()
{
return dateOfSale;
}
public void setDateOfSale(Date dateOfSale)
{
this.dateOfSale = dateOfSale;
}
}
//*******Driver class creating a new Vehicle object *******
Vehicle v1 = new Vehicle("Ford", "Fiesta", null, "123abc", "12/03/2000", 'c', 3000);