Android how to get tomorrow#39;s date(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?
推荐答案
以
日历的形式获取今天的日期.
Get today's date as a
Calendar.
增加 1 天.
用于显示目的的格式.
例如,
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DATE, 1);
// now do something with the calendar
这篇关于Android如何获取明天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android如何获取明天的日期
基础教程推荐
- 验证是否调用了所有 getter 方法 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
