//get current date
SimpleDateFormat monthFormat = new SimpleDateFormat("M");
int _currentMonth = Integer.parseInt(monthFormat.format(new Date(System.currentTimeMillis())));
SimpleDateFormat yearFormat = new SimpleDateFormat("YYYY");
int _currentYear = Integer.parseInt(yearFormat.format(new Date(System.currentTimeMillis())));
我試圖建立一個日曆視圖,並且我開始檢索當前年份和月份。然而,返回的是一個字符串,而我想要一個int在數組中使用等。BlackBerry:正在檢索當前的年月日
上面的代碼給了我一個錯誤,最有可能是由於Integer.parseInt函數。
我不能使用它嗎?什麼是檢索年,月和日的最佳方式。
你並不需要使用'Long.parseLong()'將大的文字傳遞給'Date()'構造函數。在整數字面上使用'L'後綴,例如:'new Date(13259152444455L);' – 2012-01-09 22:18:39
謝謝,我會改變 – 2012-01-10 04:12:16