Calendar,Date,long(Millis)转换

//Calendar与Date、long的转换:
  Calendar ca = Calendar.getInstance();
   Date d = ca.getTime();
   long l = ca.getTimeInMillis();
   ca.setTime(d);
   ca.setTimeInMillis(l);

//Date和long间的转换:
 Date d = new Date();
  long l = d.getTime();
  d.setTime(l);
  d = new Date(l); 

long d2;
System.out.println(d2=new Date().getTime());
new Date(d2);
new Date(1257304282376L);//要带l/L,否则会认为是int 越界

 

你可能感兴趣的:(calendar)