本文介绍了两个特定日期之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个日期20-03-2011和1-04-2011,存储为String.How我可以解析为日期格式,并计算两个日期之间的差异?
I have two dates 20-03-2011 and 1-04-2011,stored as String.How can I parse this into date format and calculate the difference between the two dates?
推荐答案以下是一个解决方案,因为有很多方法可以实现这一点:
The following is one solution, as there are numerous ways we can achieve this:
import java.util.*; int syear = 2000; int eyear = 2000; int smonth = 2;//Feb int emonth = 3;//Mar int sday = 27; int eday = 1; Date startDate = new Date(syear-1900,smonth-1,sday); Date endDate = new Date(eyear-1900,emonth-1,eday); int difInDays = (int) ((endDate.getTime() - startDate.getTime())/(1000*60*60*24));更多推荐
两个特定日期之间的区别
发布评论