gpt4 book ai didi

android - 检查今天的日期和android中的前一个日期之间的差异

转载 作者:行者123 更新时间:2023-11-30 04:38:28 27 4
gpt4 key购买 nike

我必须找出今天的日期和之前的另一个日期之间的天差。我怎样才能找到??

我写代码:

Calendar calfromDate = Calendar.getInstance();
calfromDate.set(m_nVYear, m_nVMonth, m_nVDay);
long m_lDate = calfromDate.getTimeInMillis();
Calendar calToday = Calendar.getInstance();
long today = calToday.getTimeInMillis();
Log.d("debug", "today:" +today);
Log.d("debug", "from date:" +m_lDate);
int day_difference = (int)((m_lDate - today)/(24*60*60*1000));

最佳答案

来自 http://tripoverit.blogspot.com/2007/07/java-calculate-difference-between-two.html :

public static long daysBetween(Calendar startDate, Calendar endDate) {  
Calendar date = (Calendar) startDate.clone();
long daysBetween = 0;
while (date.before(endDate)) {
date.add(Calendar.DAY_OF_MONTH, 1);
daysBetween++;
}
return daysBetween;
}

关于android - 检查今天的日期和android中的前一个日期之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6434979/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com