Android如何获取明天的日期

2022-01-11 00:00:00 calendar android java

在我的安卓应用程序中.我需要显示明天的日期,例如今天是 3 月 5 日,所以我需要显示为 3 月 6 日.我知道获取今天的日期、月份和年份的代码.

In my android application. I need to display tomorrow's date, for example today is 5th March so I need to display as 6 March. I know the code for getting today's date, month and year.

日期计算

    GregorianCalendar gc = new GregorianCalendar();
    yearat = gc.get(Calendar.YEAR);
    yearstr = Integer.toString(yearat);
    monthat = gc.get(Calendar.MONTH) + 1;
    monthstr = Integer.toString(monthat);
    dayat = gc.get(Calendar.DAY_OF_MONTH);
    daystr = Integer.toString(dayat);

如果我有代码

dayat = gc.get(Calendar.DAY_OF_MONTH) + 1;

它会显示明天的日期吗?或者只是在今天的日期上加一个?例如,如果今天是 1 月 31 日.使用上面的代码,它会显示为 1 还是 32?如果显示为 32,我需要进行哪些更改?

will it display tomorrow's date. or just add one to today's date? For example, if today is January 31. With the above code, will it display like 1 or 32? If it displays 32, what change I need to make?

推荐答案

  1. 日历的形式获取今天的日期.

  1. Get today's date as a Calendar.

增加 1 天.

用于显示目的的格式.

例如,

GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DATE, 1);
// now do something with the calendar

相关文章