2011年6月23日 星期四

get the system time - Calendar (eng. ver)

If you want to get the system time of your device, you can import


import java.util.Calendar;
               

then, use these codes as follows:

long time=System.currentTimeMillis();
final Calendar mCalendar=Calendar.getInstance();
mCalendar.setTimeInMillis(time);
int mHour=mCalendar.get(Calendar.HOUR);                        //get current hour
int mMinuts=mCalendar.get(Calendar.MINUTE);                 //get current minute
int mSecond = mCalendar.get(Calendar.SECOND);              //get current second
int mMilliSecond = mCalendar.get(Calendar.MILLISECOND);  //get milliseconds

沒有留言:

張貼留言