方式一:
import java.text.simpledateformat;
simpledateformat formatter = new simpledateformat ("yyyy年mm月dd日 hh:mm:ss");
date curdate = new date(system.currenttimemillis());
//擷取目前時間
string str = formatter.format(curdate);
方式二:
取得系統時間
1。
long time=system.currenttimemillis();
2。
final calendar mcalendar=calendar.getinstance();
mcalendar.settimeinmillis(time);
取得小時:mhour=mcalendar.get(calendar.hour);
取得分鐘:mminuts=mcalendar.get(calendar.minute);
3。
time t=new time(); // or time t=new time("gmt+8"); 加上time zone資料
t.settonow(); // 取得系統時間。
int year = t.year;
int month = t.month;
int date = t.monthday;
int hour = t.hour; // 0-23
4。
dateformat df = new simpledateformat("hh:mm:ss");
df.format(new date());
轉載:http://blog.csdn.net/chaoyu168/article/details/50729689