我有这两个方法,现在写。随着情况的发展,当我从数据库中获取数据字段时,它是BigDecimal格式。所以我决定为它写一个测试(formatDate()方法)。我将BigDecimal传递给该方法,但似乎我写了一些错误的代码。从我在例子和SimpleDateFormat API中看到的,我认为我已经正确地编写了代码,但是我似乎无法弄清楚如何让它抛出parseEx。有人能给我提示发生了什么吗?SimpleDateFormatter抛出ParseException
private void loadMap() {
//TODO: Uncomment when finished testing.
//DO OTHER STUFF
BigDecimal bd = new BigDecimal(12051998);
System.out.println(formatDate(bd));
}
private String formatDate(BigDecimal bd) {
String value = bd.toString();
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
try {
return format.parse(value);
} catch (ParseException pEx) {
logger.error(pEx);
return "Bad Date Format";
}
}
由于提前,向那,
- 约什
'BigDecimal'是用于保持日期值的奇数选择。 – GriffeyDog 2013-04-08 14:40:23
@GriffeyDog它是AS/400上用于DB2的IBM/Genelco软件。一切都很奇怪。 – ResourceReaper 2013-04-08 14:44:15
答案是好的,但你也可以考虑使用[乔达时间](http://joda-time.sourceforge.net/userguide.html) – durron597 2013-04-08 14:50:43