我正在搜索如何將字符串轉換爲日期,因此我在堆棧中找到了一些示例。 。所以我使用SimpleDateFormat並試圖解析,但我的編譯器(從AndroidStudio Gradle)給我發送此錯誤:未處理的異常:java.text.ParseException。 有我的代碼:無法將字符串轉換爲日期
public static int compareDate(String sdate1, String sdate2) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd", Locale.FRANCE);
Date date1 = simpleDateFormat.parse(sdate1); // there is the error
[...]
}
爲什麼會出現錯誤?有人可以向我解釋? 我是java的初學者,我很抱歉我的英語不好,我希望有人能幫助我。 謝謝
你能告訴我們如何你的字符串是什麼樣子? – darijan
這是與您的locale – JREN
一個問題,我在我的函數的格式輸入「2013年7月1日」的字符串 – bengous