java中的日期

来源:互联网 发布:崛起平台网络兼职 编辑:程序博客网 时间:2024/04/28 16:39


Date now = new Date(time);
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(System.currentTimeMillis()+999L*24*60*60*1000);
  //cal.setTimeInMillis(time);//以毫秒为单位设置时间
  System.out.println(cal);

  System.out.println(cal.get(1));//获得年
  System.out.println(cal.get(2)+1);//月
  System.out.println(cal.get(5));//日
  System.out.println(cal.get(11));//时?待验证
  System.out.println(cal.get(12));//分?待验证
  System.out.println(cal.get(13));//秒?待验证


  //SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
  //String str = sdf.format(now);
  //System.out.println(str);

  System.out.println(now.getYear()+1900);
  System.out.println(now.getMonth()+1);
  System.out.println(now.getDate());

  System.out.println(now.getHours());
  System.out.println(now.getMinutes());
  System.out.println(now.getSeconds());

0 0
原创粉丝点击