时间java
新文章移至
http://cffile.sinaapp.com/?p=26一、当前时间
1.Calendar now=Calendar.getInstance();
String time=now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH)+1)+"-"+now.get(Calendar.DAY_OF_MONTH)+" "
+now.get(Calendar.HOUR_OF_DAY)+":"+now.get(Calendar.MINUTE)+":"+now.get(Calendar.SECOND);
2.
24小时制
SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd" + " " + "HH:mm:ss");
String datetime = tempDate.format(new java.util.Date());
12小时制
SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd" + " " + "hh:mm:ss");
String datetime = tempDate.format(new java.util.Date());
二、程序运行时间
long begin,end,time;
Date mydate=new Date();
begin=mydate.getTime();
Date mydate2=new Date();
end=mydate2.getTime();
time=end-begin;