如何通过我的classmethod" setFormat"设置日期格式?在主?我有一个测试文件,我写了#34; d1.toString();"以及之前的其他事情。我想要的是能够在测试文件中将日期格式设置为美国格式或瑞典格式,并查看结果。
public static void setFormat(int theFormat)
{
format = theFormat;
}
public String toString()
{
if(format == SE_FORMAT)
{
date2 = Integer.toString(Year) + '-' + Integer.toString(Month) + '-' + Integer.toString(Day);
}
else if(theFormat == US_FORMAT)
{
date2 = Integer.toString(Month) + '/' + Integer.toString(Day) + '/' + Integer.toString(Year);
}
else
{
date2 = Integer.toString(Year) + '-' + Integer.toString(Month) + '-' + Integer.toString(Day);
}
return date2;
}