0
我想爲我的android應用程序獲取正確的日期,但它似乎並沒有工作。如何將日期從getDateInstance轉換爲SimpleDateFormat而不更改日期?
當我使用此代碼
String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
if(btn==v){
view.setText(currentDateTimeString);
}
我拿到打印出來作爲12月10日的正確日期,2013年
但是當我嘗試的日期總是轉換成一個簡單的日期格式,程序停止工作。
String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
SimpleDateFormat dateformat = new SimpleDateFormat("MM/FF");
String cdate = dateformat.format(currentDateTimeString);
if(btn==v){
view.setText(cdate);
}
此外,當我使用簡單的日期格式,這樣我得到一個完全不同的日期,12/02
Calendar cdate = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("MM/FF");
if(btn==v){
view.setText(sdf.format(cdate.getTime()));
}
我試圖獲取當前日期顯示爲月/日,任何幫助將不勝感激。