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

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 に答える