java得到系统时间1

来源:百度文库 编辑:神马文学网 时间:2024/04/28 19:58:47

1.
 SimpleDateFormat   sDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//注意月份MM
 String today = sDateFormat.format(new Date());

Time******2006-12-06 11:42:34
2.
int y,m,d,h,mi,s;
  Calendar cal=Calendar.getInstance();
  y=cal.get(Calendar.YEAR);
  m=cal.get(Calendar.MONTH);
  d=cal.get(Calendar.DATE);
  h=cal.get(Calendar.HOUR_OF_DAY);
  mi=cal.get(Calendar.MINUTE);
  s=cal.get(Calendar.SECOND);
  System.out.println("现在时刻是"+y+"年"+m+"月"+d+"日"+h+"时"+mi+"分"+s+"秒");


现在时刻是2006年11月6日11时43分52秒


3.
Time******2006-12-6 11:42:34
Date d=new Date();
d.toLocaleString()