[java]比较两个日期之间的天数<script src="http://blog.csdn.net/count.aspx?ID=438390&Type=Rank"></script>
java 代码
- import java.text.SimpleDateFormat;
- import java.util.Date;
- public class Tmp {
- public static void main( String argv[] ) throws Exception {
- long DAY = 24L * 60L * 60L * 1000L;
- SimpleDateFormat df = new SimpleDateFormat( "MM.dd.yyyy" );
- Date d1 = df.parse( "01.01.2001" );
- Date d2 = df.parse( "01.03.2001" );
- System.out.println( "The number days between:" );
- System.out.println( d1 );
- System.out.println( "and:" );
- System.out.println( d2 );
- System.out.println( "is: " + (( d2.getTime() - d1.getTime() ) / DAY ));
- }
- }