2013-12-11 27 views
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())); 
} 

我试图获取当前日期显示为月/日,任何帮助将不胜感激。

回答

相关问题