Android获取当前时间


  

取得系统时间

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("yyyy-MM-dd HH:mm:ss.SSS");

df.format(new Date());

   



Last Article Next article

Comment 评论



Share 分享

New Users 最新加入

  • hokurikustr

  • refrain

New comments 最新评论

test123: aasdas Details Apr 13 16:39
admin: Thanks! Details Apr 09 11:46
admin: Google map api Details Apr 09 11:46
lqj12: cooooooooool Details Apr 08 21:34
Yunhan Huang: 这个功能是如何实现的? Details Apr 08 13:23