使用SimpleDate的Android日期格式

Cou*_*son 3 android simpledateformat

我正在开发一个Android解决方案,包含12个不同的项目,我需要帮助为每个项目创建日期.这是我到目前为止:

TextView detailsPubdate = (TextView)findViewById(R.id.detailspubdate);

我希望日期看起来像这样:9月3日星期六.谢谢你的帮助!

nic*_*ild 8

如果您要查找今天的日期,可以使用该Date对象执行此操作.

Date today = new Date();//this creates a date representing this instance in time.
Run Code Online (Sandbox Code Playgroud)

然后将日期传递给SimpleDateFormat.format(Date)方法.

// "EEEE, MMMM, d" is the pattern to use to get your desired formatted date.
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM, d");
String formattedDate = sdf.format(today);
Run Code Online (Sandbox Code Playgroud)

最后,你可以将它设置String为你的TextView

detailsPubdate.setText(formattedDate);
Run Code Online (Sandbox Code Playgroud)

这是文档SimpleDateFormat.文档显示了可用于格式化Date对象的各种模式.