Android 日期:查找未来日期
我正在寻找并且一直在寻找一个很好的例子或教程,通过添加设定的天数来计算/查找未来的日期。
我有一个日期选择器,当用户单击 EditText 时打开,以便他们可以选择日期,然后我想添加比该日期还早的 56 天。然后显示一个 Toast 或对话框,其中显示日期集的未来日期。然后,在我了解并弄清楚之后,我将让我的应用程序在该日期显示通知。
不确定我是否应该使用日历或闹钟,哦,这些数据存储在 SQLite 数据库中。就像总是希望我已经提供了足够的信息让您了解我正在尝试做什么。
任何帮助、指示或建议都会很棒,因为我仍在学习 java 和 android
I am looking and have been looking for a good example or tutorial on calculating/finding a future date by adding a set number of days.
I have a date picker that opens when user clicks on EditText so they can select the date, then I'm wanting to add lets say 56 days to that date. then show a Toast or Dialog that displays the future date from the date set. Then after i learn and figure that out I'm going to have my app show a notification on that date.
not sure if i should be using calendar or alarm,, oh and this data is being stored in a SQLite DB. like always hope i have given enough info to give you an idea of what I'm trying to do.
any help, pointers or suggestions will be awesome, as i am still learning both java and android
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
currentDate:日期选择器中的日期,
天:添加到当前日期的天数
希望这会有所帮助。
currentDate: Date from date picker,
days: Number of days to be added to currentDate
Hope this would help.
为什么不使用 Calendar.add(field, amount) 呢?
是的,您可以使用 AlarmManager。我知道的不多,但我相信这样就可以了。
当然,你的问题是通用的,并没有增加具体的问题。也就是说,考虑到模式,我相信上述内容就可以了。
Why not Calendar.add(field, amount)?
From that, yes, you could use AlarmManager. I don't know much, but I believe that would do.
Of course, your question is generic and does not add an specific problem. That said, considering the pattern, I believe the above will do.
这是获取未来日期和时间的工作代码。参考:https://www.youtube.com/watch?v=2DYavHADmB8/
This is working code to get future date and time. Reference: https://www.youtube.com/watch?v=2DYavHADmB8/