格式化日历日期日历、日期

2023-09-06 03:12:27 作者:欲迷i

我只是想把日期出现像这样:

I just want the date to show up like so:

周六,2012年5月26日,在下午10:42

下面是我的code到目前为止:

Here's my code so far:

Calendar calendar = Calendar.getInstance();
String theDate = calendar.get(Calendar.MONTH) + " " + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(Calendar.YEAR);

lastclick.setText(getString(R.string.lastclick) + " " + theDate);

这显示月,日和年的数字,但得是这样做的更好的办法?是不是有这样做的像使用PHP的最新的一些简单方法()功能?

This shows the numbers of the month, day, and year, but there's got to be a better way of doing this? Isn't there some simple way of doing this like using PHP's date() function?

推荐答案

使用以下按要求的日期格式。请参阅此 LINK

Use the below to format the date as required. Refer this LINK

 Calendar calendar = Calendar.getInstance();
 lastclick.setText(getString(R.string.lastclick) + " " + String.format("%1$tA %1$tb %1$td %1$tY at %1$tI:%1$tM %1$Tp", calendar));

其中,%1 $ TA的staurday, %1 $ TB五月,

Where %1$tA for staurday, %1$tb for May,

等等...