把代码块放在其中就是了.
线程的运行的时间也是类似的
public static void testRunningTime() {
long t1 = System.currentTimeMillis();
// invoke your program here
long t2 = System.currentTimeMillis();
System.out.println("Your program has executed for "
+ (int)((t2-t1)/1000)+ " seconds "
+ ((t2-t1) % 1000) + " micro seconds");
}
/** * 计算指定日期的上一天 * * @param dateTime * 日期,格式为:yyyy-MM-dd * @return */ public static String getBeforeDay(String dateTime) { Calendar now = Calendar.getInstance(); SimpleDateFormat simpledate = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = simpledate.parse(dateTime); } catch (ParseException ex) { System.out.println("日期格式不符合要求:" + ex.getMessage()); return null; } now.setTime(date); int year = now.get(Calendar.YEAR); int month = now.get(Calendar.MONTH); int day = now.get(Calendar.DAY_OF_MONTH) - 1; now.set(year, month, day); String time = simpledate.format(now.getTime()); return time; }
return now.getActualMaximum(Calendar.DATE); /** Date end = null; between = (end.getTime() - begin.getTime()) / 1000;// 除以1000是为了转换成秒 return between; /** Date end = null; between = Math.abs(end.getTime() - begin.getTime()) / 1000;// 除以1000是为了转换成秒 return between; |