2016-02-04 84 views
0

我在日期有问题。Android:简单日期格式

比如现在是2月4日,2016年

而且我填充(我不知道确切的REM)与当前日期(DD),但我得到的结果TextView的是2016年35月。

这是我的代码:

DateFormat dateFormat1 = new SimpleDateFormat("D"); 
String cDay = dateFormat1.format(new Date()); 
Day.setText(cDay); 
+0

,你可以使用Calendar.DAY_OF_MONTH – Fustigador

回答

2

D - Day in yeard - Day in month

u可以使用如下─

DateFormat dateFormat1 = new SimpleDateFormat("dd"); 
String cDay = dateFormat1.format(new Date()); 
Day.setText(cDay); 
+0

所以首府Changsha d和小d不一样? :3 tss哈哈我不知道它XD btw现在好了谢谢 – CallMeJeo

+0

@CallMeJeo:Plz接受它:)没有不是。请参阅此链接 - http://www.java2s.com/Tutorial/Java/0040__Data-Type/SimpleDateFormat.htm – kevz

+0

感谢您的信息:) – CallMeJeo

0

试试这个代码,

public static String getDateFormat(String date) { 
     SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); 
     String convertedDate = ""; 
     try { 
      Date parseDate = dateFormat.parse(date); 
      SimpleDateFormat fmtOut = new SimpleDateFormat("yyyy-MM-dd"); 
      convertedDate = fmtOut.format(parseDate); 
     } catch (ParseException e) { 
      e.printStackTrace(); 
     } 
     return convertedDate; 
    } 

OR

public static String getTodaysDate() { 
     Calendar currentDate = Calendar.getInstance(); //Get the current date 
     SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy "); //format it as per your requirement 

     return formatter.format(currentDate.getTime()); 
    } 
0

新的SimpleDateFormat( “EEE,MMM d '' YY,H:MM一”)

0

尝试代码如下

DateFormat dateFormat1 = new SimpleDateFormat("d MMM yyyy"); 
String cDay = dateFormat1.format(new Date()); 
Day.setText(cDay); 

希望这个代码将会帮助你..

0

试试这个: -

DateTimeFormat.forPattern("d").print(DateTime.now()); 

它如果你需要的是当天返回字符串值