格式化日历日期 [英] Formatting a calendar date

查看:235
本文介绍了格式化日历日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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,

等等...

这篇关于格式化日历日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆