首页 > 移动平台 > 详细

Android获取当前时间的3中方法总结

时间:2015-09-24 22:30:12      阅读:300      评论:0      收藏:0      [点我收藏+]

今天听了一在线公开课,任务是做一个数字时钟,其中最关键的自然是获取当前的系统时间。做个简单的记录,如下:

1. 

Time time = new Time("GMT+8");
time.setToNow(); //Sets the time of the given Time object to the current time. 将事件获取对象置为当前时间
		
System.out.println(time.hour);
System.out.println(time.minute);
System.out.println(time.second);

2.

private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String str = sdf.format(new Date());

3.

Calendar calendar = Calendar.getInstance();

int hour = calendar.HOUR_OF_DAY;
int minute = calendar.MINUTE;
int second = calendar.SECOND;

  

Android获取当前时间的3中方法总结

原文:http://www.cnblogs.com/hoosway/p/4836701.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!