[英]Getting the Difference between a date and system date android
I am trying to achieve a functionality for a membership App but am find some difficulties working with Dates.我正在尝试实现会员应用程序的功能,但发现在使用日期时遇到了一些困难。
I retrieve a startDate from the DB which comes as "YYYY-MM-dd".我从数据库中检索了一个startDate ,它以“YYYY-MM-dd”的形式出现。 What I wish to achieve is to calculate the difference in day from the currentDate to the startDate store it in a variable int result
我希望实现的是计算从currentDate到startDate 的天数差异,将其存储在变量int result 中
if result > 365 textView.setText("Membership expired");如果结果 > 365 textView.setText("会员资格过期");
If anyone can point me in the right direction, I'll be really grateful.如果有人能指出我正确的方向,我将不胜感激。
您可以使用下面的代码来计算当前日期和开始日期之间的天数。
(currentDate - startDate) / (1000*3600*24)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.