1

Androidの日付ピッカーに入力された日から50日を計算する方法.

例 ユーザーが 2013 年 2 月 23 日を選択した場合、xx/xx/xxxx から 50 日目はどうなるでしょうか 同様に 100 日目 200 日目 賢明な 1000 日目のように このロジックで私を助けてください

4

2 に答える 2

2

私があなたの質問を理解している限り、あなたはそのようなことを試みることができます:

// this const is 24 hours in milliseconds: 24 hours in day, 60 min. in one hour, 60 sec. in one min., 1000 ms. in one sec.
private static final int TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000;
//...
Date dateYouChose;
Date dateYouChosePlus50Days = new Date(dateYouChose.getTime() + (50 * TWENTY_FOUR_HOURS));

更新しました:

だから、多分それはあなたにとって良いでしょう(しかし、注意してください、私はこのコードをテストしていません。おそらく私は何かを間違えました):

final DatePicker datePicker;

final Button btnDisplayCelebrationTimes;

final TextView txtDatePlus50;
final TextView txtDatePlus100;

// ...

btnDisplayCelebrationTimes.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");

        final GregorianCalendar gregorianCalendar;

        gregorianCalendar = new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(),
                datePicker.getDayOfMonth());
        gregorianCalendar.add(Calendar.DAY_OF_MONTH, 50);
        final Date datePlus50 = gregorianCalendar.getTime();

        txtDatePlus50.setText(dateFormat.format(datePlus50));

        gregorianCalendar = new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(),
                datePicker.getDayOfMonth());
        gregorianCalendar.add(Calendar.DAY_OF_MONTH, 100);
        final Date datePlus100 = gregorianCalendar.getTime();

        txtDatePlus100.setText(dateFormat.format(datePlus100));
    }
});
于 2013-06-04T06:47:28.190 に答える