package Date;
import java.util.Calendar;
import java.util.Date;
public class DateDemo3 {
/**
* 日期对象之间的转换
*/
public static void main(String[] args) {
long now = System.currentTimeMillis();
Date dd = new Date();
System.out.printf("%d %d",dd.getDate(),dd.getDay());
java.sql.Date sdd = new java.sql.Date(now);
Calendar cal = Calendar.getInstance();
//long->Date
dd.setTime(now);
//Date->Calendar
cal.setTime(dd);
//Calendar->Date
dd = cal.getTime();
//Date->long
now = dd.getTime();
//sd -> ud
dd = sdd;
//ud -> sd
//若不是同一类型不能进行强制类型转换
sdd = new java.sql.Date(dd.getTime());
System.out.println(sdd);
}
}
阅读(595) | 评论(0) | 转发(0) |