我想將作爲String傳遞給SimpleDateFormat對象的Timestamp值轉換爲Time Value,但它會引發Unparseable日期異常。java.text.ParseException:在Java中將時間戳值轉換爲時間時的不可解析日期異常
java.text.ParseException: Unparseable date: "Thu Jan 1 17:45:00 UTC+0530 1970"
請找到下面的代碼,我已經實現了(不工作):
static SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
static SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
static SimpleDateFormat outputFormatTime = new SimpleDateFormat("HH:mm:ss");
public static String convertUtcDateStringToTime(String utcDateValue) throws Exception
{
Date parsedDate = dateFormat.parse(utcDateValue);
String returnDate=outputFormatTime.format(inputFormat.parse(parsedDate.toString()));
return returnDate;
}
如果我使用下面的下面所提到
The Value which i am passing is Thu Jan 1 17:45:00 UTC+0530 1970
柏迪我得到一個異常代碼它工作正常,我(工作),但它是我想要避免日期的折舊功能..
@SuppressWarnings("deprecation")
public static String convertUtcDateStringToTime(String utcDateValue) throws Exception
{
Date dateValue=new Date(utcDateValue);
Date parsedDate = dateFormat.parse(dateValue.toString());
String returnDate=outputFormatTime.format(inputFormat.parse(parsedDate.toString()));
return returnDate;
}
請指導我執行我錯過的邏輯。提前致謝。
..謝謝親愛的..朋友..回答也幫助了我:-) –