Java 获取当前时间(毫秒级)以及计算时间的常用代码

  • 获取当前时间的几种方式(毫秒级)
System.out.println(new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss:SSS").format(new Date()));
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
System.out.println(new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss:SSS").format(date));
Calendar calendar = Calendar.getInstance();
int YY = calendar.get(Calendar.YEAR) ;
int MM = calendar.get(Calendar.MONTH)+1;
int DD = calendar.get(Calendar.DATE);
int HH = calendar.get(Calendar.HOUR_OF_DAY);
int mm = calendar.get(Calendar.MINUTE);
int SS = calendar.get(Calendar.SECOND);
int MI = calendar.get(Calendar.MILLISECOND);
System.out.println(YY + "/" + MM + "/" + DD + "-" + HH + ":" + mm + ":" + SS + ":" + MI);

 

  • 计算时间的几种用法

你可能感兴趣的:(Java基础)