import java.text.SimpleDateFormat;import java.time.LocalDate;import java.time.Period;import java.time.format.DateTimeFormatter;import java.util.Date;public class DateChal { public static void main(String[] args) { // TODO Auto-generated method stub LocalDate start=LocalDate.parse("2018-10-25"); LocalDate end=LocalDate.parse("2019-10-25"); Period p=Period.between(start, end); System.out.println("Number of days "+p.getDays()); }}o/p:Number of days 0 如何解决问题?还请解释什么是错的?
4 回答
慕虎7371278
TA贡献1802条经验 获得超4个赞
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
Date firstDate = sdf.parse("06/30/2017");
Date secondDate = sdf.parse("06/30/2018");
long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
System.out.println(diff);
添加回答
举报
0/150
提交
取消