我在字符串對象中有日期。我想轉換成Date對象。創建一個接收字符串對象並以dd-MM-yyyy格式返回Date對象的函數
Date getDateFmString(String dateString)
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date convertedCurrentDate = sdf.parse(dateString);
return convertedCurrentDate ;
}
上面的函數返回下面的輸出。
Fri Apr 22 00:00:00 IST 2016
- ,但我想在這個格式 '2016年3月1日' 只有
- 功能輸出應該只需要字符串。
- 函數應該返回Date對象。
它是不是已經在正確的格式? – 4castle
這是字符串對象我希望它在Date對象中 –
但是爲了什麼目的?是驗證字符串的格式? – 4castle