Android如何获得明天的约会 [英] Android how to get tomorrow's date

查看:94
本文介绍了Android如何获得明天的约会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用程序中。我需要显示明天的日期,例如今天是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天。

用于显示目的的格式。

例如,

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

这篇关于Android如何获得明天的约会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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