/*
要求是这样的把字符串"2007127"转换成时间格式输出,然后再求离当前时间有多少天
*/
package org.new79.com;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestTaday {
public static void main(String[] args){
try {
Date d=new Date();
SimpleDateFormat sf =new SimpleDateFormat();
String today=sf.format(d);
System.out.println(today);
System.out.println(TestTaday.getCompareDate("2007127", today));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String s="2007017";
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
try {
Date d1 = sdf.parse(s);
java.sql.Date dd=new java.sql.Date(d1.getTime());
System.out.println("转换后的时间是="+dd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static long getCompareDate(String startDate,String endDate) throws Exception {
SimpleDateFormat formatter=new SimpleDateFormat("yyyyMMdd");
Date date1=formatter.parse(startDate);
Date date2=formatter.parse(endDate);
long l = date2.getTime() - date1.getTime();
long d = l/(24*60*60*1000);
return d;
}
}
=========================================================================
需要优化,等待中。
要求是这样的把字符串"2007127"转换成时间格式输出,然后再求离当前时间有多少天
*/
package org.new79.com;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestTaday {
public static void main(String[] args){
try {
Date d=new Date();
SimpleDateFormat sf =new SimpleDateFormat();
String today=sf.format(d);
System.out.println(today);
System.out.println(TestTaday.getCompareDate("2007127", today));
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String s="2007017";
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");
try {
Date d1 = sdf.parse(s);
java.sql.Date dd=new java.sql.Date(d1.getTime());
System.out.println("转换后的时间是="+dd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static long getCompareDate(String startDate,String endDate) throws Exception {
SimpleDateFormat formatter=new SimpleDateFormat("yyyyMMdd");
Date date1=formatter.parse(startDate);
Date date2=formatter.parse(endDate);
long l = date2.getTime() - date1.getTime();
long d = l/(24*60*60*1000);
return d;
}
}
=========================================================================
需要优化,等待中。