我想知道今天和2010.5.1的时间差(用天计算)
我写的代码如下:
Date start=new Date(2010,5,1);
Date now=new Date();
Long shijian=now.getTime()-start.getTime();
Integer day=(int)(shijian/(24*3600*1000));
String str=day.toString();//把天数改成String类型可是有问题啊,高手帮我解决一下~
我写的代码如下:
Date start=new Date(2010,5,1);
Date now=new Date();
Long shijian=now.getTime()-start.getTime();
Integer day=(int)(shijian/(24*3600*1000));
String str=day.toString();//把天数改成String类型可是有问题啊,高手帮我解决一下~
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();c1.set(2010,4,1);
System.out.println(c2.get(Calendar.DAY_OF_YEAR) - c1.get(Calendar.DAY_OF_YEAR));System.out.println((c2.getTime().getTime() - c1.getTime().getTime())/(24 * 3600 *1000));
public Date()
Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecondpublic Date(int year,int month, int date).
Allocates a Date object and initializes it so that it represents midnight, local time, at the beginning of the day specified by the year, month, and date arguments. Parameters:
year - the year minus 1900. //这里是重点,是你出错的原因所在。要先将year减1900。
month - the month between 0-11.
date - the day of the month between 1-31.
Date start=new Date(110,5,1); //将2010减1900
Date now=new Date();
Long shijian=now.getTime()-start.getTime();
Integer day=(int)(shijian/(24*3600*1000));
String str=day.toString();//把天数改成String类型
中c2.getTime().getTime()的第二个getTime是什么意思 啊?
month - the month between 0-11.
date - the day of the month between 1-31.