"String str------->Date d:
通过:SimpleDateFormat sdf
sdf.parse(s);---->Date d
d.getTime();
d.setTime(long time);
Date d------->String str:
sdf.format(d);
SimpleDateFormat成员方法:
* public final String format(Date d)
* public Date parse(String source)" "public static void main(String[] args) throws ParseException {
String birthday = ""1983年07月08日"";
String today = ""2088年6月6日"";
SimpleDateFormat sdf = new SimpleDateFormat(""yyyy年MM月dd日"");
Date d1 = sdf.parse(birthday);
Date d2 = sdf.parse(today);
long time = d2.getTime() - d1.getTime(); //毫秒值相减
System.out.println(time / 1000 / 60 / 60 / 24 );
}
Date d = new Date(); //获取当前时间对象
SimpleDateFormat sdf = new SimpleDateFormat(""yyyy/MM/dd HH:mm:ss"");//创建日期格式化类对象
System.out.println(sdf.format(d)); //将日期对象转换为字符串
DateFormat df1 = DateFormat.getDateInstance(); //相当于父类引用指向子类对象,右边的方法返回一个子类对象"
|
|