Cannot format given Object as a Date

java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:310)
at java.text.Format.format(Format.java:157)
at com.nantian.sms.service.CoreOnLineTransactionService.findCoreTransactions(CoreOnLineTransactionService.java:103)
at com.nantian.sms.service.CoreOnLineTransactionService.getCoreRealtimeData(CoreOnLineTransactionService.java:70)
==============================================================================================================================

String transDate=otherMsg.substring(0,10);//********************************************************************************
//交易日期 //2
String strDateFormat = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);

 

//注意:这儿传入的应该是date;但是现在传入的是字符串
String date=sdf.format(transDate);
//应改为:
Date tradeDate=sdf.parse(transDate) ;//解析为日期
String date=sdf.format(tradeDate);//然后再格式化

posted @ 2020-01-23 11:29  Curedfisher  阅读(5076)  评论(0编辑  收藏  举报