嗨我想在android textview中打印“4月23日星期一”格式的日期,我也想打印前几天。例如:“4月22日星期日”,“4月21日星期六”。我找到了很多,但无法得到任何可以使用相同格式的东西。提前完成。
答案 0 :(得分:3)
看看: SimpleDateFormat
PS: 回答Jon Skeet提出的问题:
private static final String DATE_FORMAT_ND = "EEE d'nd' MMMM";
private static final String DATE_FORMAT_RD = "EEE d'rd' MMMM";
private static final String DATE_FORMAT_ST = "EEE d'st' MMMM";
private static final String DATE_FORMAT_TH = "EEE d'th' MMMM";
private static final String DATE_DAY_NUMBER = "d";
public static String FormatDate( Date date_ )
{
String format = null;
SimpleDateFormat dayNumberFormat = new SimpleDateFormat( DATE_DAY_NUMBER );
String daySource = dayNumberFormat.format( date_ );
int day = Integer.parseInt( daySource );
switch( day )
{
case 1:
case 21:
case 31:
format = DATE_FORMAT_ST;
break;
case 2:
case 22:
format = DATE_FORMAT_ND;
break;
case 3:
case 23:
format = DATE_FORMAT_RD;
break;
case 4:
case 24:
case 5:
case 25:
case 6:
case 26:
case 7:
case 27:
case 8:
case 28:
case 9:
case 29:
case 10:
case 30:
format = DATE_FORMAT_TH;
break;
}
SimpleDateFormat dateFormat = new SimpleDateFormat( format );
String result = dateFormat.format( date_ );
return result;
}
只有简单的日期格式和一点点编码......
在昨天的日期调用它: - date.setText(FormatDate(new Date(new Date()。getTime() - 86400000)));
答案 1 :(得分:1)
你可以试试这个:
DateFormat format = new SimpleDateFormat("EEEE d MMMM yyyy");
System.out.println(format.format(new Date()));