0

您好,我想显示当前日期。我试着这样做:

calendar c = Calendar.getInstance();
System.out.println("Current time => "+c.getTime());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
TextView txtView = (TextView)findViewById(R.id.tvDate);
txtView.setText("Current Date and Time : "+formattedDate);

但它不会在我的 textView 中显示日期。

有没有更好的方法来显示相同​​的日期?我想要这样:4 月 22 日,星期一

4

2 回答 2

2

您应该查看SimpleDateFormat.

简单日期格式

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

应该

SimpleDateFormat df = new SimpleDateFormat("EEEE, MMMMM dddd");
于 2012-11-01T20:11:00.373 回答
1
Date now = new Date();
String str = DateUtils.getRelativeDateTimeString(

        this, // Suppose you are in an activity or other Context subclass

        now.getTime(), // The time to display

        MINUTE_IN_MILLIS, // The resolution. This will display only minutes 
                          // (no "3 seconds ago"

        WEEK_IN_MILLIS, // The maximum resolution at which the time will switch 
                         // to default date instead of spans. This will not 
                         // display "3 weeks ago" but a full date instead

        0); // Eventual flags

MINUTE_IN_MILLIS 和 YEAR_IN_MILLIS 的其他值包括:

SECOND_IN_MILLIS
MINUTE_IN_MILLIS
HOUR_IN_MILLIS
DAY_IN_MILLIS
WEEK_IN_MILLIS
YEAR_IN_MILLIS
Any custom value in milliseconds

然后将文本设置为

txtView.setText("Current Date and Time : "+now);
于 2012-11-01T20:23:53.073 回答